Spaces:
Sleeping
Sleeping
Update frontend.py
Browse files- frontend.py +65 -11
frontend.py
CHANGED
@@ -63,6 +63,7 @@ with st.sidebar:
|
|
63 |
tab1, tab2 = st.tabs(["π§ Analyze Review", "π Bulk Reviews"])
|
64 |
|
65 |
# === SINGLE REVIEW ANALYSIS ===
|
|
|
66 |
with tab1:
|
67 |
st.title("π ChurnSight AI β Product Feedback Assistant")
|
68 |
st.markdown("Analyze feedback to detect churn risk, extract pain points, and support product decisions.")
|
@@ -93,7 +94,6 @@ with tab1:
|
|
93 |
try:
|
94 |
model_used = None if sentiment_model == "Auto-detect" else sentiment_model
|
95 |
payload = {
|
96 |
-
|
97 |
"text": st.session_state.review,
|
98 |
"model": model_used or "distilbert-base-uncased-finetuned-sst-2-english",
|
99 |
"industry": industry,
|
@@ -133,7 +133,6 @@ with tab1:
|
|
133 |
else:
|
134 |
st.info("β
No specific pain points were detected.")
|
135 |
|
136 |
-
|
137 |
try:
|
138 |
st.session_state.churn_log.append({
|
139 |
"timestamp": datetime.now(),
|
@@ -150,12 +149,28 @@ with tab1:
|
|
150 |
sentiment = data["sentiment"]["label"].lower()
|
151 |
churn = data.get("churn_risk", "")
|
152 |
pain = data.get("pain_points", [])
|
|
|
153 |
if sentiment == "positive" and churn == "Low Risk":
|
154 |
-
suggestions = [
|
|
|
|
|
|
|
|
|
|
|
155 |
elif churn == "High Risk":
|
156 |
-
suggestions = [
|
|
|
|
|
|
|
|
|
|
|
157 |
else:
|
158 |
-
suggestions = [
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
selected_q = st.selectbox("π‘ Suggested Questions", ["Type your own..."] + suggestions)
|
161 |
q_input = st.text_input("π Your Question") if selected_q == "Type your own..." else selected_q
|
@@ -196,19 +211,40 @@ with tab1:
|
|
196 |
# === BULK REVIEW ANALYSIS ===
|
197 |
with tab2:
|
198 |
st.title("π Bulk Feedback Analysis")
|
199 |
-
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
payload = {
|
203 |
-
"reviews":
|
204 |
"model": "distilbert-base-uncased-finetuned-sst-2-english" if sentiment_model == "Auto-detect" else sentiment_model,
|
205 |
"industry": None,
|
206 |
"product_category": None,
|
207 |
"device": None,
|
208 |
"aspects": st.session_state.use_aspects,
|
209 |
"intelligence": st.session_state.intelligence_mode,
|
210 |
-
"explain_bulk":
|
211 |
-
|
212 |
}
|
213 |
try:
|
214 |
res = requests.post(f"{backend_url}/bulk/?token={api_token}", json=payload)
|
@@ -216,6 +252,24 @@ with tab2:
|
|
216 |
results = res.json().get("results", [])
|
217 |
df = pd.DataFrame(results)
|
218 |
st.dataframe(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
st.download_button("β¬οΈ Export Results CSV", df.to_csv(index=False), "bulk_results.csv")
|
220 |
else:
|
221 |
try:
|
|
|
63 |
tab1, tab2 = st.tabs(["π§ Analyze Review", "π Bulk Reviews"])
|
64 |
|
65 |
# === SINGLE REVIEW ANALYSIS ===
|
66 |
+
|
67 |
with tab1:
|
68 |
st.title("π ChurnSight AI β Product Feedback Assistant")
|
69 |
st.markdown("Analyze feedback to detect churn risk, extract pain points, and support product decisions.")
|
|
|
94 |
try:
|
95 |
model_used = None if sentiment_model == "Auto-detect" else sentiment_model
|
96 |
payload = {
|
|
|
97 |
"text": st.session_state.review,
|
98 |
"model": model_used or "distilbert-base-uncased-finetuned-sst-2-english",
|
99 |
"industry": industry,
|
|
|
133 |
else:
|
134 |
st.info("β
No specific pain points were detected.")
|
135 |
|
|
|
136 |
try:
|
137 |
st.session_state.churn_log.append({
|
138 |
"timestamp": datetime.now(),
|
|
|
149 |
sentiment = data["sentiment"]["label"].lower()
|
150 |
churn = data.get("churn_risk", "")
|
151 |
pain = data.get("pain_points", [])
|
152 |
+
|
153 |
if sentiment == "positive" and churn == "Low Risk":
|
154 |
+
suggestions = [
|
155 |
+
"What features impressed the user?",
|
156 |
+
"Would they recommend the product?",
|
157 |
+
"What benefits did they mention?",
|
158 |
+
"What made their experience smooth?"
|
159 |
+
]
|
160 |
elif churn == "High Risk":
|
161 |
+
suggestions = [
|
162 |
+
"What made the user upset?",
|
163 |
+
"Is this user likely to churn?",
|
164 |
+
"What were the major complaints?",
|
165 |
+
"What could improve their experience?"
|
166 |
+
]
|
167 |
else:
|
168 |
+
suggestions = [
|
169 |
+
"What are the key takeaways?",
|
170 |
+
"Is there any concern raised?",
|
171 |
+
"Did the user express dissatisfaction?",
|
172 |
+
"Is this feedback actionable?"
|
173 |
+
]
|
174 |
|
175 |
selected_q = st.selectbox("π‘ Suggested Questions", ["Type your own..."] + suggestions)
|
176 |
q_input = st.text_input("π Your Question") if selected_q == "Type your own..." else selected_q
|
|
|
211 |
# === BULK REVIEW ANALYSIS ===
|
212 |
with tab2:
|
213 |
st.title("π Bulk Feedback Analysis")
|
214 |
+
|
215 |
+
st.markdown("#### π₯ Upload CSV or Paste Reviews")
|
216 |
+
uploaded_file = st.file_uploader("Upload a CSV with a 'review' column", type=["csv"])
|
217 |
+
bulk_input = st.text_area("Or paste multiple reviews (one per line)", height=180)
|
218 |
+
|
219 |
+
reviews = []
|
220 |
+
|
221 |
+
if uploaded_file is not None:
|
222 |
+
try:
|
223 |
+
df_csv = pd.read_csv(uploaded_file)
|
224 |
+
if "review" in df_csv.columns:
|
225 |
+
reviews = df_csv["review"].dropna().astype(str).tolist()
|
226 |
+
else:
|
227 |
+
st.warning("CSV must contain a 'review' column.")
|
228 |
+
except Exception as e:
|
229 |
+
st.error(f"CSV error: {e}")
|
230 |
+
elif bulk_input.strip():
|
231 |
+
reviews = [line.strip() for line in bulk_input.split("\\n") if line.strip()]
|
232 |
+
|
233 |
+
st.markdown("#### π§ Bulk Analysis Configuration")
|
234 |
+
explain_bulk = st.checkbox("π§ Generate Explanations", value=st.session_state.get("use_explain_bulk", False))
|
235 |
+
enable_followups = st.checkbox("π¬ Generate Follow-Up Q&A", value=True)
|
236 |
+
|
237 |
+
if st.button("π Analyze Bulk") and reviews:
|
238 |
payload = {
|
239 |
+
"reviews": reviews,
|
240 |
"model": "distilbert-base-uncased-finetuned-sst-2-english" if sentiment_model == "Auto-detect" else sentiment_model,
|
241 |
"industry": None,
|
242 |
"product_category": None,
|
243 |
"device": None,
|
244 |
"aspects": st.session_state.use_aspects,
|
245 |
"intelligence": st.session_state.intelligence_mode,
|
246 |
+
"explain_bulk": explain_bulk,
|
247 |
+
"follow_up": [["What is the issue here?", "What could be improved?"]] * len(reviews) if enable_followups else None
|
248 |
}
|
249 |
try:
|
250 |
res = requests.post(f"{backend_url}/bulk/?token={api_token}", json=payload)
|
|
|
252 |
results = res.json().get("results", [])
|
253 |
df = pd.DataFrame(results)
|
254 |
st.dataframe(df)
|
255 |
+
|
256 |
+
if any("follow_up" in r for r in results):
|
257 |
+
st.markdown("### π¬ Follow-Up Answers")
|
258 |
+
for r in results:
|
259 |
+
st.markdown(f"**Review:** {r['review']}")
|
260 |
+
if isinstance(r.get("follow_up"), list):
|
261 |
+
for ans in r["follow_up"]:
|
262 |
+
st.info(ans)
|
263 |
+
elif "follow_up" in r:
|
264 |
+
st.info(r["follow_up"])
|
265 |
+
|
266 |
+
if "churn_risk" in df.columns:
|
267 |
+
st.markdown("### π Churn Risk Chart")
|
268 |
+
churn_summary = df["churn_risk"].value_counts().reset_index()
|
269 |
+
churn_summary.columns = ["Churn Risk", "Count"]
|
270 |
+
fig = px.pie(churn_summary, names="Churn Risk", values="Count", title="Churn Risk Distribution")
|
271 |
+
st.plotly_chart(fig, use_container_width=True)
|
272 |
+
|
273 |
st.download_button("β¬οΈ Export Results CSV", df.to_csv(index=False), "bulk_results.csv")
|
274 |
else:
|
275 |
try:
|