Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
import re
|
|
@@ -34,7 +109,10 @@ set_background("New3.jpg")
|
|
| 34 |
|
| 35 |
# Title and Description
|
| 36 |
st.title("📊 Telugu Sentiment Analysis")
|
| 37 |
-
st.markdown(
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Load the model pipeline
|
| 40 |
@st.cache_resource
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
# from transformers import pipeline
|
| 3 |
+
# import re
|
| 4 |
+
# import base64
|
| 5 |
+
|
| 6 |
+
# # Page Configuration
|
| 7 |
+
# st.set_page_config(page_title="Telugu Sentiment Analysis", layout="centered", )
|
| 8 |
+
|
| 9 |
+
# # Function to Encode Image
|
| 10 |
+
# def get_base64(file_path):
|
| 11 |
+
# with open(file_path, "rb") as f:
|
| 12 |
+
# data = f.read()
|
| 13 |
+
# return base64.b64encode(data).decode()
|
| 14 |
+
|
| 15 |
+
# # Set Background from Image
|
| 16 |
+
# def set_background(image_path):
|
| 17 |
+
# img_data = get_base64(image_path)
|
| 18 |
+
# st.markdown(
|
| 19 |
+
# f"""
|
| 20 |
+
# <style>
|
| 21 |
+
# .stApp {{
|
| 22 |
+
# background-image: url("data:image/jpg;base64,{img_data}");
|
| 23 |
+
# background-size: cover;
|
| 24 |
+
# background-position: center;
|
| 25 |
+
# background-repeat: no-repeat;
|
| 26 |
+
# }}
|
| 27 |
+
# </style>
|
| 28 |
+
# """,
|
| 29 |
+
# unsafe_allow_html=True
|
| 30 |
+
# )
|
| 31 |
+
|
| 32 |
+
# # Set the background
|
| 33 |
+
# set_background("New3.jpg")
|
| 34 |
+
|
| 35 |
+
# # Title and Description
|
| 36 |
+
# st.title("📊 Telugu Sentiment Analysis")
|
| 37 |
+
# st.markdown("Analyze the sentiment (Positive, Negative, Neutral) of a given **Telugu** sentence using a fine-tuned BERT model.", #1affff)
|
| 38 |
+
|
| 39 |
+
# # Load the model pipeline
|
| 40 |
+
# @st.cache_resource
|
| 41 |
+
# def load_pipeline():
|
| 42 |
+
# return pipeline("text-classification", model="Adityaganesh/Telugu_Sentiment_Analysis")
|
| 43 |
+
|
| 44 |
+
# pipe = load_pipeline()
|
| 45 |
+
|
| 46 |
+
# # Text Preprocessing
|
| 47 |
+
# def preprocess_text(text):
|
| 48 |
+
# text = text.strip()
|
| 49 |
+
# text = re.sub(r"\s+", " ", text)
|
| 50 |
+
# return text
|
| 51 |
+
|
| 52 |
+
# # User Input
|
| 53 |
+
# user_input = st.text_area("Enter Telugu Text:", height=200, placeholder="ఇక్కడ మీ తెలుగు వాక్యాన్ని నమోదు చేయండి...")
|
| 54 |
+
|
| 55 |
+
# if st.button("🔍 Analyze Sentiment"):
|
| 56 |
+
# if user_input.strip() == "":
|
| 57 |
+
# st.warning("దయచేసి కొన్ని తెలుగు వాక్యాలు నమోదు చేయండి.")
|
| 58 |
+
# else:
|
| 59 |
+
# clean_text = preprocess_text(user_input)
|
| 60 |
+
# with st.spinner("Analyzing sentiment..."):
|
| 61 |
+
# result = pipe(clean_text)[0]
|
| 62 |
+
# idx = int(result['label'].split('_')[1])
|
| 63 |
+
|
| 64 |
+
# if idx == 0:
|
| 65 |
+
# sentiment = "😐 Neutral"
|
| 66 |
+
# color = "gray"
|
| 67 |
+
# elif idx == 1:
|
| 68 |
+
# sentiment = "😊 Positive"
|
| 69 |
+
# color = "green"
|
| 70 |
+
# else:
|
| 71 |
+
# sentiment = "😠 Negative"
|
| 72 |
+
# color = "red"
|
| 73 |
+
|
| 74 |
+
# st.markdown(f"### Prediction: <span style='color:{color}'>{sentiment}</span>", unsafe_allow_html=True)
|
| 75 |
+
|
| 76 |
import streamlit as st
|
| 77 |
from transformers import pipeline
|
| 78 |
import re
|
|
|
|
| 109 |
|
| 110 |
# Title and Description
|
| 111 |
st.title("📊 Telugu Sentiment Analysis")
|
| 112 |
+
st.markdown(
|
| 113 |
+
"<h4 style='color:#1affff;'>Analyze the sentiment (Positive, Negative, Neutral) of a given <b>Telugu</b> sentence using a fine-tuned BERT model.</h4>",
|
| 114 |
+
unsafe_allow_html=True
|
| 115 |
+
)
|
| 116 |
|
| 117 |
# Load the model pipeline
|
| 118 |
@st.cache_resource
|