File size: 5,055 Bytes
3f824e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4591d22
 
 
464e30a
8291ed6
8bc5288
275dcf0
8bc5288
464e30a
 
 
 
 
 
 
8bc5288
464e30a
8bc5288
 
 
 
464e30a
8bc5288
 
 
 
 
 
 
 
 
464e30a
 
8bc5288
 
3f824e3
cc81276
80a7467
 
 
 
 
3f824e3
 
8291ed6
275dcf0
4591d22
 
 
 
 
 
8bc5288
4591d22
 
 
 
 
275dcf0
 
4591d22
275dcf0
4591d22
 
 
 
275dcf0
4591d22
 
464e30a
4591d22
45f0c94
275dcf0
4591d22
45f0c94
275dcf0
4591d22
45f0c94
275dcf0
4591d22
a51e2dc
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# 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"""
#         <style>
#         .stApp {{
#             background-image: url("data:image/jpg;base64,{img_data}");
#             background-size: cover;
#             background-position: center;
#             background-repeat: no-repeat;
#         }}
#         </style>
#         """,
#         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: <span style='color:{color}'>{sentiment}</span>", 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"""
        <style>
        .stApp {{
            background-image: url("data:image/jpg;base64,{img_data}");
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }}
        </style>
        """,
        unsafe_allow_html=True
    )

# Set the background
set_background("New3.jpg")

# Title and Description
st.markdown(
    "<h1 style='text-align: center; color:#1affff;'> Telugu Sentiment Analysis</h1>",
    unsafe_allow_html=True
)

st.markdown(
    "<h4 style='text-align: center; color:#1affff;'>Analyze the sentiment (Positive, Negative, Neutral) of a given <b>Telugu</b> sentence using a fine-tuned BERT model.</h4>",
    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"<h3><span style='color:#1affff'>Prediction:</span> <span style='color:{color}'>{sentiment}</span></h3>",
    unsafe_allow_html=True)