Adityaganesh commited on
Commit
464e30a
Β·
verified Β·
1 Parent(s): 8bc5288

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -1,18 +1,25 @@
1
  import streamlit as st
2
- import transformers
3
  from transformers import pipeline
4
  import re
 
5
 
6
  # Page Configuration
7
  st.set_page_config(page_title="Telugu Sentiment Analysis", layout="centered")
8
 
9
- # Background Image via Custom CSS
 
 
 
 
 
 
10
  def set_background(image_path):
 
11
  st.markdown(
12
  f"""
13
  <style>
14
  .stApp {{
15
- background-image: url("{image_path}");
16
  background-size: cover;
17
  background-position: center;
18
  background-repeat: no-repeat;
@@ -22,7 +29,8 @@ def set_background(image_path):
22
  unsafe_allow_html=True
23
  )
24
 
25
- set_background("New3.jpg") # Make sure New3.jpg is in the same directory
 
26
 
27
  # Title and Description
28
  st.title("πŸ“Š Telugu Sentiment Analysis")
@@ -52,7 +60,7 @@ if st.button("πŸ” Analyze Sentiment"):
52
  with st.spinner("Analyzing sentiment..."):
53
  result = pipe(clean_text)[0]
54
  idx = int(result['label'].split('_')[1])
55
-
56
  if idx == 0:
57
  sentiment = "😐 Neutral"
58
  color = "gray"
@@ -63,4 +71,4 @@ if st.button("πŸ” Analyze Sentiment"):
63
  sentiment = "😠 Negative"
64
  color = "red"
65
 
66
- st.markdown(f"### Prediction: <span style='color:{color}'>{sentiment}</span>", unsafe_allow_html=True)
 
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;
 
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")
 
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"
 
71
  sentiment = "😠 Negative"
72
  color = "red"
73
 
74
+ st.markdown(f"### Prediction: <span style='color:{color}'>{sentiment}</span>", unsafe_allow_html=True)