Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app-4.py +31 -0
- requirements-4.txt +5 -0
app-4.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
3 |
+
|
4 |
+
# Load the tokenizer and model
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("OatNapat/finetuned_yelp")
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained("OatNapat/finetuned_yelp")
|
7 |
+
|
8 |
+
# Create a sentiment analysis pipeline with the explicit tokenizer
|
9 |
+
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
10 |
+
|
11 |
+
st.title("Sentiment Analysis App")
|
12 |
+
user_input = st.text_input("ป้อนประโยคเพื่อวิเคราะห์ความรู้สึก:")
|
13 |
+
if user_input:
|
14 |
+
result = nlp(user_input)
|
15 |
+
sentiment_label = result[0]["label"]
|
16 |
+
sentiment_score = result[0]["score"]
|
17 |
+
|
18 |
+
# Define explanations for sentiment labels
|
19 |
+
sentiment_explanations = {
|
20 |
+
"LABEL_0": "Very negative",
|
21 |
+
"LABEL_1": "Negative",
|
22 |
+
"LABEL_2": "Neutral",
|
23 |
+
"LABEL_3": "Positive",
|
24 |
+
"LABEL_4": "Very positive"
|
25 |
+
}
|
26 |
+
|
27 |
+
# Get the explanation for the sentiment label
|
28 |
+
sentiment_explanation = sentiment_explanations.get(sentiment_label, "Unknown")
|
29 |
+
|
30 |
+
st.write(f"Sentiment: {sentiment_explanation}")
|
31 |
+
st.write(f"Confidence: {sentiment_score:.4f}")
|
requirements-4.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
torch
|
3 |
+
transformers
|
4 |
+
pandas
|
5 |
+
altair<5
|