Hasitha16 commited on
Commit
3b153d2
ยท
verified ยท
1 Parent(s): fa41d98

Update frontend.py

Browse files
Files changed (1) hide show
  1. frontend.py +18 -5
frontend.py CHANGED
@@ -6,6 +6,7 @@ import base64
6
  from io import BytesIO
7
  from PIL import Image
8
  import os
 
9
 
10
  st.set_page_config(page_title="NeuroPulse AI", page_icon="๐Ÿง ", layout="wide")
11
 
@@ -18,11 +19,14 @@ if "review" not in st.session_state:
18
  st.session_state.review = ""
19
  if "dark_mode" not in st.session_state:
20
  st.session_state.dark_mode = False
 
 
21
 
22
  # Shared Sidebar Controls
23
  with st.sidebar:
24
  st.header("โš™๏ธ Global Settings")
25
  st.session_state.dark_mode = st.toggle("๐ŸŒ™ Dark Mode", value=st.session_state.dark_mode)
 
26
 
27
  api_token = st.text_input("๐Ÿ” API Token", type="password")
28
  backend_url = st.text_input("๐Ÿ–ฅ๏ธ Backend URL", value="http://0.0.0.0:8000")
@@ -47,11 +51,11 @@ with st.sidebar:
47
  use_aspects = st.checkbox("๐Ÿ”ฌ Enable Aspect Analysis")
48
  use_smart_summary = st.checkbox("๐Ÿง  Use Smart Summary (Single)")
49
  use_smart_summary_bulk = st.checkbox("๐Ÿง  Smart Summary for Bulk")
 
50
  follow_up = st.text_input("๐Ÿ” Follow-up Question")
51
  voice_lang = st.selectbox("๐Ÿ”ˆ Voice Language", ["en", "fr", "es", "de", "hi", "zh"])
52
 
53
  # Text-to-Speech Helper
54
-
55
  def speak(text, lang='en'):
56
  tts = gTTS(text, lang=lang)
57
  mp3 = BytesIO()
@@ -98,7 +102,9 @@ with tab1:
98
  "aspects": use_aspects,
99
  "follow_up": follow_up,
100
  "product_category": product_category,
101
- "device": device_type
 
 
102
  }
103
  headers = {"X-API-Key": api_token}
104
  params = {"smart": "1"} if use_smart_summary else {}
@@ -122,6 +128,9 @@ with tab1:
122
  if data.get("follow_up"):
123
  st.subheader("๐Ÿง  Follow-Up Response")
124
  st.warning(data["follow_up"])
 
 
 
125
  else:
126
  st.error(f"โŒ API Error: {res.status_code}")
127
  except Exception as e:
@@ -137,8 +146,8 @@ with tab2:
137
  """, unsafe_allow_html=True)
138
 
139
  with st.expander("๐Ÿ“„ Sample CSV"):
140
- with open("sample_reviews.csv", "rb") as f:
141
- st.download_button("โฌ‡๏ธ Download sample CSV", f, file_name="sample_reviews.csv")
142
 
143
  uploaded_file = st.file_uploader("๐Ÿ“ Upload your CSV", type="csv")
144
 
@@ -164,7 +173,8 @@ with tab2:
164
  "aspects": use_aspects,
165
  "industry": df["industry"].tolist(),
166
  "product_category": df["product_category"].tolist(),
167
- "device": df["device"].tolist()
 
168
  }
169
  headers = {"X-API-Key": api_token}
170
  params = {"smart": "1"} if use_smart_summary_bulk else {}
@@ -174,6 +184,9 @@ with tab2:
174
  results = pd.DataFrame(res.json()["results"])
175
  results["summary_type"] = "Smart" if use_smart_summary_bulk else "Standard"
176
  st.dataframe(results)
 
 
 
177
  st.download_button("โฌ‡๏ธ Download Results CSV", results.to_csv(index=False), "bulk_results.csv", mime="text/csv")
178
  else:
179
  st.error(f"โŒ Bulk Analysis Failed: {res.status_code}")
 
6
  from io import BytesIO
7
  from PIL import Image
8
  import os
9
+ import plotly.express as px
10
 
11
  st.set_page_config(page_title="NeuroPulse AI", page_icon="๐Ÿง ", layout="wide")
12
 
 
19
  st.session_state.review = ""
20
  if "dark_mode" not in st.session_state:
21
  st.session_state.dark_mode = False
22
+ if "intelligence_mode" not in st.session_state:
23
+ st.session_state.intelligence_mode = True
24
 
25
  # Shared Sidebar Controls
26
  with st.sidebar:
27
  st.header("โš™๏ธ Global Settings")
28
  st.session_state.dark_mode = st.toggle("๐ŸŒ™ Dark Mode", value=st.session_state.dark_mode)
29
+ st.session_state.intelligence_mode = st.toggle("๐Ÿง  Intelligence Mode", value=st.session_state.intelligence_mode)
30
 
31
  api_token = st.text_input("๐Ÿ” API Token", type="password")
32
  backend_url = st.text_input("๐Ÿ–ฅ๏ธ Backend URL", value="http://0.0.0.0:8000")
 
51
  use_aspects = st.checkbox("๐Ÿ”ฌ Enable Aspect Analysis")
52
  use_smart_summary = st.checkbox("๐Ÿง  Use Smart Summary (Single)")
53
  use_smart_summary_bulk = st.checkbox("๐Ÿง  Smart Summary for Bulk")
54
+ verbosity = st.radio("๐Ÿ—ฃ๏ธ Response Style", ["Brief", "Detailed"])
55
  follow_up = st.text_input("๐Ÿ” Follow-up Question")
56
  voice_lang = st.selectbox("๐Ÿ”ˆ Voice Language", ["en", "fr", "es", "de", "hi", "zh"])
57
 
58
  # Text-to-Speech Helper
 
59
  def speak(text, lang='en'):
60
  tts = gTTS(text, lang=lang)
61
  mp3 = BytesIO()
 
102
  "aspects": use_aspects,
103
  "follow_up": follow_up,
104
  "product_category": product_category,
105
+ "device": device_type,
106
+ "verbosity": verbosity,
107
+ "intelligence": st.session_state.intelligence_mode
108
  }
109
  headers = {"X-API-Key": api_token}
110
  params = {"smart": "1"} if use_smart_summary else {}
 
128
  if data.get("follow_up"):
129
  st.subheader("๐Ÿง  Follow-Up Response")
130
  st.warning(data["follow_up"])
131
+ if data.get("explanation"):
132
+ st.subheader("๐Ÿงฎ Explain This")
133
+ st.markdown(data["explanation"])
134
  else:
135
  st.error(f"โŒ API Error: {res.status_code}")
136
  except Exception as e:
 
146
  """, unsafe_allow_html=True)
147
 
148
  with st.expander("๐Ÿ“„ Sample CSV"):
149
+ with open("sample_reviews.csv", "rb") as f:
150
+ st.download_button("โฌ‡๏ธ Download sample CSV", f, file_name="sample_reviews.csv")
151
 
152
  uploaded_file = st.file_uploader("๐Ÿ“ Upload your CSV", type="csv")
153
 
 
173
  "aspects": use_aspects,
174
  "industry": df["industry"].tolist(),
175
  "product_category": df["product_category"].tolist(),
176
+ "device": df["device"].tolist(),
177
+ "intelligence": st.session_state.intelligence_mode
178
  }
179
  headers = {"X-API-Key": api_token}
180
  params = {"smart": "1"} if use_smart_summary_bulk else {}
 
184
  results = pd.DataFrame(res.json()["results"])
185
  results["summary_type"] = "Smart" if use_smart_summary_bulk else "Standard"
186
  st.dataframe(results)
187
+ if "sentiment" in results:
188
+ fig = px.pie(results, names="sentiment", title="Sentiment Distribution")
189
+ st.plotly_chart(fig)
190
  st.download_button("โฌ‡๏ธ Download Results CSV", results.to_csv(index=False), "bulk_results.csv", mime="text/csv")
191
  else:
192
  st.error(f"โŒ Bulk Analysis Failed: {res.status_code}")