# import streamlit as st # from transformers import pipeline # import re # import base64 # # Page Configuration # st.set_page_config(page_title="Telugu Sentiment Analysis", layout="centered", ) # # Function to Encode Image # def get_base64(file_path): # with open(file_path, "rb") as f: # data = f.read() # return base64.b64encode(data).decode() # # Set Background from Image # def set_background(image_path): # img_data = get_base64(image_path) # st.markdown( # f""" # # """, # unsafe_allow_html=True # ) # # Set the background # set_background("New3.jpg") # # Title and Description # st.title("📊 Telugu Sentiment Analysis") # st.markdown("Analyze the sentiment (Positive, Negative, Neutral) of a given **Telugu** sentence using a fine-tuned BERT model.", #1affff) # # Load the model pipeline # @st.cache_resource # def load_pipeline(): # return pipeline("text-classification", model="Adityaganesh/Telugu_Sentiment_Analysis") # pipe = load_pipeline() # # Text Preprocessing # def preprocess_text(text): # text = text.strip() # text = re.sub(r"\s+", " ", text) # return text # # User Input # user_input = st.text_area("Enter Telugu Text:", height=200, placeholder="ఇక్కడ మీ తెలుగు వాక్యాన్ని నమోదు చేయండి...") # if st.button("🔍 Analyze Sentiment"): # if user_input.strip() == "": # st.warning("దయచేసి కొన్ని తెలుగు వాక్యాలు నమోదు చేయండి.") # else: # clean_text = preprocess_text(user_input) # with st.spinner("Analyzing sentiment..."): # result = pipe(clean_text)[0] # idx = int(result['label'].split('_')[1]) # if idx == 0: # sentiment = "😐 Neutral" # color = "gray" # elif idx == 1: # sentiment = "😊 Positive" # color = "green" # else: # sentiment = "😠 Negative" # color = "red" # st.markdown(f"### Prediction: {sentiment}", unsafe_allow_html=True) import streamlit as st from transformers import pipeline import re import base64 # Page Configuration st.set_page_config(page_title="Telugu Sentiment Analysis", layout="centered") # Function to Encode Image def get_base64(file_path): with open(file_path, "rb") as f: data = f.read() return base64.b64encode(data).decode() # Set Background from Image def set_background(image_path): img_data = get_base64(image_path) st.markdown( f""" """, unsafe_allow_html=True ) # Set the background set_background("New3.jpg") # Title and Description st.markdown( "

Telugu Sentiment Analysis

", unsafe_allow_html=True ) st.markdown( "

Analyze the sentiment (Positive, Negative, Neutral) of a given Telugu sentence using a fine-tuned BERT model.

", unsafe_allow_html=True ) # Load the model pipeline @st.cache_resource def load_pipeline(): return pipeline("text-classification", model="Adityaganesh/Telugu_Sentiment_Analysis") pipe = load_pipeline() # Text Preprocessing def preprocess_text(text): text = text.strip() text = re.sub(r"\s+", " ", text) return text # User Input user_input = st.text_area("Enter Telugu Text:", height=200, placeholder="ఇక్కడ మీ తెలుగు వాక్యాన్ని నమోదు చేయండి...") if st.button("🔍 Analyze Sentiment"): if user_input.strip() == "": st.warning("దయచేసి కొన్ని తెలుగు వాక్యాలు నమోదు చేయండి.") else: clean_text = preprocess_text(user_input) with st.spinner("Analyzing sentiment..."): result = pipe(clean_text)[0] idx = int(result['label'].split('_')[1]) if idx == 0: sentiment = " Neutral" color = "gray" elif idx == 1: sentiment = " Positive" color = "green" else: sentiment = " Negative" color = "red" st.markdown( f"

Prediction: {sentiment}

", unsafe_allow_html=True)