Spaces:
Running
Running
Update frontend.py
Browse files- frontend.py +30 -19
frontend.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
# --- import statements remain unchanged ---
|
2 |
import streamlit as st
|
3 |
import requests
|
4 |
import pandas as pd
|
@@ -9,13 +8,14 @@ from PIL import Image
|
|
9 |
import os
|
10 |
import plotly.express as px
|
11 |
|
12 |
-
# --- Config ---
|
13 |
st.set_page_config(page_title="NeuroPulse AI", page_icon="๐ง ", layout="wide")
|
|
|
|
|
14 |
logo_path = "logo.png"
|
15 |
if os.path.exists(logo_path):
|
16 |
st.image(logo_path, width=180)
|
17 |
|
18 |
-
#
|
19 |
if "review" not in st.session_state:
|
20 |
st.session_state.review = ""
|
21 |
if "dark_mode" not in st.session_state:
|
@@ -25,7 +25,7 @@ if "intelligence_mode" not in st.session_state:
|
|
25 |
if "trigger_example_analysis" not in st.session_state:
|
26 |
st.session_state.trigger_example_analysis = False
|
27 |
|
28 |
-
#
|
29 |
if st.session_state.dark_mode:
|
30 |
st.markdown("""
|
31 |
<style>
|
@@ -44,11 +44,24 @@ if st.session_state.dark_mode:
|
|
44 |
</style>
|
45 |
""", unsafe_allow_html=True)
|
46 |
|
47 |
-
#
|
48 |
with st.sidebar:
|
49 |
st.header("โ๏ธ Global Settings")
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
DEFAULT_DEMO_TOKEN = "my-secret-key"
|
54 |
api_token = st.text_input("๐ API Token", value=DEFAULT_DEMO_TOKEN, type="password")
|
@@ -80,7 +93,7 @@ with st.sidebar:
|
|
80 |
verbosity = st.radio("๐ฃ๏ธ Response Style", ["Brief", "Detailed"])
|
81 |
voice_lang = st.selectbox("๐ Voice Language", ["en", "fr", "es", "de", "hi", "zh"])
|
82 |
|
83 |
-
#
|
84 |
def speak(text, lang='en'):
|
85 |
tts = gTTS(text, lang=lang)
|
86 |
mp3 = BytesIO()
|
@@ -90,15 +103,13 @@ def speak(text, lang='en'):
|
|
90 |
mp3.seek(0)
|
91 |
return mp3
|
92 |
|
93 |
-
# --- Tabs ---
|
94 |
tab1, tab2 = st.tabs(["๐ง Single Review", "๐ Bulk CSV"])
|
95 |
|
96 |
-
#
|
97 |
-
# SINGLE REVIEW TAB
|
98 |
-
# -------------------
|
99 |
with tab1:
|
100 |
st.title("๐ง NeuroPulse AI โ Multimodal Review Analyzer")
|
101 |
st.markdown("<div style='font-size:16px;color:#888;'>Minimum 20โ50 words recommended.</div>", unsafe_allow_html=True)
|
|
|
102 |
review = st.text_area("๐ Enter Review", value=st.session_state.review, height=180)
|
103 |
|
104 |
col1, col2, col3 = st.columns(3)
|
@@ -135,8 +146,7 @@ with tab1:
|
|
135 |
"follow_up": None,
|
136 |
"product_category": product_category,
|
137 |
"verbosity": verbosity,
|
138 |
-
"intelligence": st.session_state.intelligence_mode
|
139 |
-
"explain": True
|
140 |
}
|
141 |
headers = {"x-api-key": st.session_state.get("api_token", api_token)}
|
142 |
params = {"smart": "1"} if use_smart_summary else {}
|
@@ -157,10 +167,7 @@ with tab1:
|
|
157 |
st.metric("๐ Sentiment", data["sentiment"]["label"], delta=f"{data['sentiment']['score']:.2%}")
|
158 |
st.info(f"๐ข Emotion: {data['emotion']}")
|
159 |
|
160 |
-
|
161 |
-
st.subheader("๐งฎ Explanation")
|
162 |
-
st.markdown(data["explanation"])
|
163 |
-
|
164 |
st.markdown("### ๐ Got questions?")
|
165 |
st.info("๐ฌ Ask a follow-up question about this review.")
|
166 |
sample_questions = [
|
@@ -170,7 +177,11 @@ with tab1:
|
|
170 |
"What are the improvement areas?"
|
171 |
]
|
172 |
selected_q = st.selectbox("๐ก Sample Questions", ["Type your own..."] + sample_questions)
|
173 |
-
|
|
|
|
|
|
|
|
|
174 |
|
175 |
if custom_q:
|
176 |
with st.spinner("Thinking..."):
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
import pandas as pd
|
|
|
8 |
import os
|
9 |
import plotly.express as px
|
10 |
|
|
|
11 |
st.set_page_config(page_title="NeuroPulse AI", page_icon="๐ง ", layout="wide")
|
12 |
+
|
13 |
+
# Logo
|
14 |
logo_path = "logo.png"
|
15 |
if os.path.exists(logo_path):
|
16 |
st.image(logo_path, width=180)
|
17 |
|
18 |
+
# Session State
|
19 |
if "review" not in st.session_state:
|
20 |
st.session_state.review = ""
|
21 |
if "dark_mode" not in st.session_state:
|
|
|
25 |
if "trigger_example_analysis" not in st.session_state:
|
26 |
st.session_state.trigger_example_analysis = False
|
27 |
|
28 |
+
# Dark Mode Style
|
29 |
if st.session_state.dark_mode:
|
30 |
st.markdown("""
|
31 |
<style>
|
|
|
44 |
</style>
|
45 |
""", unsafe_allow_html=True)
|
46 |
|
47 |
+
# Sidebar Controls
|
48 |
with st.sidebar:
|
49 |
st.header("โ๏ธ Global Settings")
|
50 |
+
|
51 |
+
# Dark Mode Toggle with refresh
|
52 |
+
if st.toggle("๐ Dark Mode", value=st.session_state.dark_mode):
|
53 |
+
if not st.session_state.dark_mode:
|
54 |
+
st.session_state.dark_mode = True
|
55 |
+
st.rerun()
|
56 |
+
else:
|
57 |
+
if st.session_state.dark_mode:
|
58 |
+
st.session_state.dark_mode = False
|
59 |
+
st.rerun()
|
60 |
+
|
61 |
+
if st.toggle("๐ง Intelligence Mode", value=st.session_state.intelligence_mode):
|
62 |
+
st.session_state.intelligence_mode = True
|
63 |
+
else:
|
64 |
+
st.session_state.intelligence_mode = False
|
65 |
|
66 |
DEFAULT_DEMO_TOKEN = "my-secret-key"
|
67 |
api_token = st.text_input("๐ API Token", value=DEFAULT_DEMO_TOKEN, type="password")
|
|
|
93 |
verbosity = st.radio("๐ฃ๏ธ Response Style", ["Brief", "Detailed"])
|
94 |
voice_lang = st.selectbox("๐ Voice Language", ["en", "fr", "es", "de", "hi", "zh"])
|
95 |
|
96 |
+
# TTS Function
|
97 |
def speak(text, lang='en'):
|
98 |
tts = gTTS(text, lang=lang)
|
99 |
mp3 = BytesIO()
|
|
|
103 |
mp3.seek(0)
|
104 |
return mp3
|
105 |
|
|
|
106 |
tab1, tab2 = st.tabs(["๐ง Single Review", "๐ Bulk CSV"])
|
107 |
|
108 |
+
# --- SINGLE REVIEW TAB ---
|
|
|
|
|
109 |
with tab1:
|
110 |
st.title("๐ง NeuroPulse AI โ Multimodal Review Analyzer")
|
111 |
st.markdown("<div style='font-size:16px;color:#888;'>Minimum 20โ50 words recommended.</div>", unsafe_allow_html=True)
|
112 |
+
|
113 |
review = st.text_area("๐ Enter Review", value=st.session_state.review, height=180)
|
114 |
|
115 |
col1, col2, col3 = st.columns(3)
|
|
|
146 |
"follow_up": None,
|
147 |
"product_category": product_category,
|
148 |
"verbosity": verbosity,
|
149 |
+
"intelligence": st.session_state.intelligence_mode
|
|
|
150 |
}
|
151 |
headers = {"x-api-key": st.session_state.get("api_token", api_token)}
|
152 |
params = {"smart": "1"} if use_smart_summary else {}
|
|
|
167 |
st.metric("๐ Sentiment", data["sentiment"]["label"], delta=f"{data['sentiment']['score']:.2%}")
|
168 |
st.info(f"๐ข Emotion: {data['emotion']}")
|
169 |
|
170 |
+
# Follow-up Section
|
|
|
|
|
|
|
171 |
st.markdown("### ๐ Got questions?")
|
172 |
st.info("๐ฌ Ask a follow-up question about this review.")
|
173 |
sample_questions = [
|
|
|
177 |
"What are the improvement areas?"
|
178 |
]
|
179 |
selected_q = st.selectbox("๐ก Sample Questions", ["Type your own..."] + sample_questions)
|
180 |
+
|
181 |
+
if selected_q != "Type your own...":
|
182 |
+
custom_q = selected_q
|
183 |
+
else:
|
184 |
+
custom_q = st.text_input("๐ Ask a follow-up")
|
185 |
|
186 |
if custom_q:
|
187 |
with st.spinner("Thinking..."):
|