narinsak unawong commited on
Commit
c9e1183
·
verified ·
1 Parent(s): 23559f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -13
app.py CHANGED
@@ -1,18 +1,35 @@
1
-
2
  import streamlit as st
3
- import pickle
 
 
 
 
 
 
 
 
 
 
4
 
5
- # Load the model
6
- with open('sentiment_pipeline.pkl', 'rb') as file:
7
- loaded_model = pickle.load(file)
 
8
 
9
- # Streamlit app title
10
- st.title("Sentiment Analysis App")
 
 
11
 
12
- # Text input for user to enter a sentence
13
- user_input = st.text_input("Enter a sentence:")
14
 
15
- # Predict sentiment when user inputs text
16
- if user_input:
17
- prediction = loaded_model.predict([user_input])[0]
18
- st.write("Prediction:", "Positive" if prediction == 1 else "Negative")
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis model
5
+ model_name = "poom-sci/WangchanBERTa-finetuned-sentiment"
6
+ sentiment_analyzer = pipeline('sentiment-analysis', model=model_name)
7
+
8
+ # Streamlit app
9
+ st.title("Thai Sentiment Analysis App")
10
+
11
+ # Input text
12
+ text_input = st.text_area("Enter Thai text for sentiment analysis", "ขอความเห็นหน่อย... ")
13
 
14
+ # Button to trigger analysis
15
+ if st.button("Analyze Sentiment"):
16
+ # Analyze sentiment using the model
17
+ results = sentiment_analyzer([text_input])
18
 
19
+ # Extract sentiment and score
20
+ sentiment = results[0]['label']
21
+ score = results[0]['score']
22
+
23
 
24
+ # Display result as progress bars
25
+ st.subheader("Sentiment Analysis Result:")
26
 
27
+ if sentiment == 'pos':
28
+ st.success(f"Positive Sentiment (Score: {score:.2f})")
29
+ st.progress(score)
30
+ elif sentiment == 'neg':
31
+ st.error(f"Negative Sentiment (Score: {score:.2f})")
32
+ st.progress(score)
33
+ else:
34
+ st.warning(f"Neutral Sentiment (Score: {score:.2f})")
35
+ st.progress(score)