Adityaganesh commited on
Commit
4591d22
·
verified ·
1 Parent(s): 6cb37ec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import re
4
+
5
+ # Title and Description
6
+ st.set_page_config(page_title="Telugu Sentiment Analysis", layout="centered")
7
+ st.title("📊 Telugu Sentiment Analysis")
8
+ st.markdown("Analyze the sentiment (Positive, Negative, Neutral) of a given **Telugu** sentence using a fine-tuned BERT model.")
9
+
10
+ # Load the model pipeline
11
+ @st.cache_resource
12
+ def load_pipeline():
13
+ return pipeline("text-classification", model="Adityaganesh/Telugu_Sentiment_Analysis")
14
+
15
+ pipe = load_pipeline()
16
+
17
+ # Optional: Text Preprocessing (basic cleaning)
18
+ def preprocess_text(text):
19
+ text = text.strip()
20
+ text = re.sub(r"\s+", " ", text)
21
+ return text
22
+
23
+ # User Input
24
+ user_input = st.text_area("Enter Telugu Text:", height=200, placeholder="ఇక్కడ మీ తెలుగు వాక్యాన్ని నమోదు చేయండి...")
25
+
26
+ if st.button("🔍 Analyze Sentiment"):
27
+ if user_input.strip() == "":
28
+ st.warning("దయచేసి కొన్ని తెలుగు వాక్యాలు నమోదు చేయండి.")
29
+ else:
30
+ clean_text = preprocess_text(user_input)
31
+ with st.spinner("Analyzing sentiment..."):
32
+ result = pipe(clean_text)[0]
33
+ idx = int(result['label'].split('_')[1])
34
+
35
+ if idx == 0:
36
+ sentiment = "😐 Neutral"
37
+ color = "gray"
38
+ elif idx == 1:
39
+ sentiment = "😊 Positive"
40
+ color = "green"
41
+ else:
42
+ sentiment = "😠 Negative"
43
+ color = "red"
44
+
45
+ st.markdown(f"### Prediction: <span style='color:{color}'>{sentiment}</span>", unsafe_allow_html=True)
46
+ st.markdown(f"**Confidence:** `{result['score']:.2f}`")