Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,41 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load the
|
| 5 |
classifier = pipeline("text-classification", model="Mpavan45/Telugu_Sentimental_Analysis")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
st.
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Example test cases
|
| 12 |
st.subheader("Try one of the following examples:")
|
|
|
|
| 13 |
examples = [
|
| 14 |
"ఈ song చాలా catchy గా ఉంది",
|
| 15 |
"నీ attitude చాల బాగుంది",
|
|
@@ -19,41 +45,33 @@ examples = [
|
|
| 19 |
"నేను ఈ వార్తలకు చాలా బాధపడ్డాను",
|
| 20 |
]
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
#
|
| 43 |
if st.button("Analyze Sentiment"):
|
| 44 |
-
if text_input:
|
| 45 |
result = classifier(text_input)
|
| 46 |
raw_label = result[0]['label']
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 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:
|
| 59 |
-
st.
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the sentiment analysis model
|
| 5 |
classifier = pipeline("text-classification", model="Mpavan45/Telugu_Sentimental_Analysis")
|
| 6 |
|
| 7 |
+
# Custom CSS for radium glow effect
|
| 8 |
+
st.markdown("""
|
| 9 |
+
<style>
|
| 10 |
+
.radium-title {
|
| 11 |
+
font-size: 40px;
|
| 12 |
+
text-align: center;
|
| 13 |
+
color: #fff;
|
| 14 |
+
padding: 10px;
|
| 15 |
+
border-radius: 10px;
|
| 16 |
+
background: linear-gradient(90deg, #ff416c, #ff4b2b);
|
| 17 |
+
box-shadow: 0 0 20px #ff416c, 0 0 30px #ff4b2b;
|
| 18 |
+
}
|
| 19 |
+
.radium-label {
|
| 20 |
+
font-size: 24px;
|
| 21 |
+
font-weight: bold;
|
| 22 |
+
color: white;
|
| 23 |
+
padding: 10px;
|
| 24 |
+
border-radius: 8px;
|
| 25 |
+
background: linear-gradient(90deg, #36d1dc, #5b86e5);
|
| 26 |
+
display: inline-block;
|
| 27 |
+
margin-top: 10px;
|
| 28 |
+
}
|
| 29 |
+
</style>
|
| 30 |
+
""", unsafe_allow_html=True)
|
| 31 |
+
|
| 32 |
+
# Display title
|
| 33 |
+
st.markdown('<div class="radium-title">Sentiment Analysis with BERT</div>', unsafe_allow_html=True)
|
| 34 |
+
st.write("This app uses a fine-tuned BERT model to classify Telugu text as Positive, Negative, or Neutral.")
|
| 35 |
|
| 36 |
# Example test cases
|
| 37 |
st.subheader("Try one of the following examples:")
|
| 38 |
+
|
| 39 |
examples = [
|
| 40 |
"ఈ song చాలా catchy గా ఉంది",
|
| 41 |
"నీ attitude చాల బాగుంది",
|
|
|
|
| 45 |
"నేను ఈ వార్తలకు చాలా బాధపడ్డాను",
|
| 46 |
]
|
| 47 |
|
| 48 |
+
# Show examples in 3 rows × 2 columns
|
| 49 |
+
example_input = ""
|
| 50 |
+
for i in range(0, len(examples), 2):
|
| 51 |
+
cols = st.columns(2)
|
| 52 |
+
for j in range(2):
|
| 53 |
+
if i + j < len(examples):
|
| 54 |
+
example = examples[i + j]
|
| 55 |
+
if cols[j].button(example[:30] + "..."):
|
| 56 |
+
example_input = example
|
| 57 |
+
|
| 58 |
+
# Take input text
|
| 59 |
+
text_input = st.text_area("Enter text to analyze sentiment:", value=example_input, height=150)
|
| 60 |
+
|
| 61 |
+
# Sentiment label and emoji
|
| 62 |
+
label_map = {
|
| 63 |
+
"LABEL_0": ("Negative", "😞"),
|
| 64 |
+
"LABEL_1": ("Neutral", "😐"),
|
| 65 |
+
"LABEL_2": ("Positive", "😊")
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
# On click, analyze sentiment
|
| 69 |
if st.button("Analyze Sentiment"):
|
| 70 |
+
if text_input.strip():
|
| 71 |
result = classifier(text_input)
|
| 72 |
raw_label = result[0]['label']
|
| 73 |
+
sentiment, emoji = label_map.get(raw_label, (raw_label, ""))
|
| 74 |
+
|
| 75 |
+
st.markdown(f'<div class="radium-label">Sentiment: {sentiment} {emoji}</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
else:
|
| 77 |
+
st.warning("Please enter some text to analyze!")
|