Spaces:
Sleeping
Sleeping
Chonnikarn
commited on
Commit
•
003e64c
1
Parent(s):
85ab74a
Upload 2 files
Browse files- app_senti_65130701929.py +37 -0
- requirements (1).txt +2 -0
app_senti_65130701929.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
# Load the sentiment analysis model
|
7 |
+
model_name = "poom-sci/WangchanBERTa-finetuned-sentiment"
|
8 |
+
sentiment_analyzer = pipeline('sentiment-analysis', model=model_name)
|
9 |
+
|
10 |
+
# Streamlit app
|
11 |
+
st.title("Thai Sentiment Analysis App")
|
12 |
+
|
13 |
+
# Input text
|
14 |
+
text_input = st.text_area("Enter Thai text for sentiment analysis", "ขอความเห็นหน่อย... ")
|
15 |
+
|
16 |
+
# Button to trigger analysis
|
17 |
+
if st.button("Analyze Sentiment"):
|
18 |
+
# Analyze sentiment using the model
|
19 |
+
results = sentiment_analyzer([text_input])
|
20 |
+
|
21 |
+
# Extract sentiment and score
|
22 |
+
sentiment = results[0]['label']
|
23 |
+
score = results[0]['score']
|
24 |
+
|
25 |
+
|
26 |
+
# Display result as progress bars
|
27 |
+
st.subheader("Sentiment Analysis Result:")
|
28 |
+
|
29 |
+
if sentiment == 'pos':
|
30 |
+
st.success(f"Positive Sentiment (Score: {score:.2f})")
|
31 |
+
st.progress(score)
|
32 |
+
elif sentiment == 'neg':
|
33 |
+
st.error(f"Negative Sentiment (Score: {score:.2f})")
|
34 |
+
st.progress(score)
|
35 |
+
else:
|
36 |
+
st.warning(f"Neutral Sentiment (Score: {score:.2f})")
|
37 |
+
st.progress(score)
|
requirements (1).txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|