Update app.py
Browse files
app.py
CHANGED
|
@@ -6,45 +6,53 @@ classifier = pipeline("text-classification", model="Mpavan45/Telugu_Sentimental_
|
|
| 6 |
|
| 7 |
# Define the Streamlit interface
|
| 8 |
st.title("Sentiment Analysis with BERT")
|
| 9 |
-
st.write("This app uses a fine-tuned BERT model to classify text as positive or
|
| 10 |
|
| 11 |
# Example test cases
|
| 12 |
st.subheader("Try one of the following examples:")
|
| 13 |
examples = [
|
| 14 |
-
|
| 15 |
-
|
| 16 |
"ఆమె behavior rude",
|
| 17 |
"ఈ ఆహారం చాలా చెడుగా ఉంది",
|
| 18 |
"నాకు ఈ రోజు చాలా సంతోషంగా ఉంది",
|
| 19 |
"నేను ఈ వార్తలకు చాలా బాధపడ్డాను",
|
| 20 |
-
|
| 21 |
]
|
| 22 |
|
| 23 |
for example in examples:
|
| 24 |
if st.button(f"Test: {example[:30]}..."):
|
| 25 |
result = classifier(example)
|
| 26 |
-
|
| 27 |
confidence = result[0]['score']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
st.write(f"Sentiment: {sentiment}")
|
| 29 |
st.write(f"Confidence: {confidence:.4f}")
|
| 30 |
st.text_area("Analysis of your text", example, height=150)
|
| 31 |
|
| 32 |
# Take input text from the user
|
| 33 |
text_input = st.text_area("Enter text to analyze sentiment:")
|
| 34 |
-
label_map = {
|
| 35 |
-
"LABEL_0": "Negative",
|
| 36 |
-
"LABEL_1": "Neutral",
|
| 37 |
-
"LABEL_2": "Positive"
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
|
| 41 |
# When the user clicks the button, classify the sentiment
|
| 42 |
if st.button("Analyze Sentiment"):
|
| 43 |
if text_input:
|
| 44 |
result = classifier(text_input)
|
| 45 |
-
|
| 46 |
confidence = result[0]['score']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
sentiment = label_map.get(raw_label, raw_label)
|
|
|
|
| 48 |
st.write(f"Sentiment: {sentiment}")
|
| 49 |
st.write(f"Confidence: {confidence:.4f}")
|
| 50 |
else:
|
|
|
|
| 6 |
|
| 7 |
# Define the Streamlit interface
|
| 8 |
st.title("Sentiment Analysis with BERT")
|
| 9 |
+
st.write("This app uses a fine-tuned BERT model to classify text as positive, negative, or neutral sentiment.")
|
| 10 |
|
| 11 |
# Example test cases
|
| 12 |
st.subheader("Try one of the following examples:")
|
| 13 |
examples = [
|
| 14 |
+
"ఈ song చాలా catchy గా ఉంది",
|
| 15 |
+
"నీ attitude చాల బాగుంది",
|
| 16 |
"ఆమె behavior rude",
|
| 17 |
"ఈ ఆహారం చాలా చెడుగా ఉంది",
|
| 18 |
"నాకు ఈ రోజు చాలా సంతోషంగా ఉంది",
|
| 19 |
"నేను ఈ వార్తలకు చాలా బాధపడ్డాను",
|
|
|
|
| 20 |
]
|
| 21 |
|
| 22 |
for example in examples:
|
| 23 |
if st.button(f"Test: {example[:30]}..."):
|
| 24 |
result = classifier(example)
|
| 25 |
+
raw_label = result[0]['label']
|
| 26 |
confidence = result[0]['score']
|
| 27 |
+
|
| 28 |
+
label_map = {
|
| 29 |
+
"LABEL_0": "Negative",
|
| 30 |
+
"LABEL_1": "Neutral",
|
| 31 |
+
"LABEL_2": "Positive"
|
| 32 |
+
}
|
| 33 |
+
sentiment = label_map.get(raw_label, raw_label)
|
| 34 |
+
|
| 35 |
st.write(f"Sentiment: {sentiment}")
|
| 36 |
st.write(f"Confidence: {confidence:.4f}")
|
| 37 |
st.text_area("Analysis of your text", example, height=150)
|
| 38 |
|
| 39 |
# Take input text from the user
|
| 40 |
text_input = st.text_area("Enter text to analyze sentiment:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# When the user clicks the button, classify the sentiment
|
| 43 |
if st.button("Analyze Sentiment"):
|
| 44 |
if text_input:
|
| 45 |
result = classifier(text_input)
|
| 46 |
+
raw_label = result[0]['label']
|
| 47 |
confidence = result[0]['score']
|
| 48 |
+
|
| 49 |
+
label_map = {
|
| 50 |
+
"LABEL_0": "Negative",
|
| 51 |
+
"LABEL_1": "Neutral",
|
| 52 |
+
"LABEL_2": "Positive"
|
| 53 |
+
}
|
| 54 |
sentiment = label_map.get(raw_label, raw_label)
|
| 55 |
+
|
| 56 |
st.write(f"Sentiment: {sentiment}")
|
| 57 |
st.write(f"Confidence: {confidence:.4f}")
|
| 58 |
else:
|