Spaces:
Running
Running
Update frontend.py
Browse files- frontend.py +24 -15
frontend.py
CHANGED
|
@@ -76,37 +76,45 @@ tab1, tab2 = st.tabs(["π§ Analyze Review", "π Bulk Reviews"])
|
|
| 76 |
with tab1:
|
| 77 |
st.title("π ChurnSight AI β Product Feedback Assistant")
|
| 78 |
st.markdown("Analyze feedback to detect churn risk, extract pain points, and support product decisions.")
|
|
|
|
| 79 |
review = st.text_area("π Enter Customer Feedback", value=st.session_state.review, height=180)
|
| 80 |
st.session_state.review = review
|
| 81 |
|
|
|
|
| 82 |
col1, col2, col3 = st.columns(3)
|
| 83 |
-
|
| 84 |
-
st.
|
| 85 |
-
|
| 86 |
-
st.
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
|
| 97 |
if st.session_state.review and (analyze or st.session_state.trigger_example_analysis):
|
| 98 |
with st.spinner("Analyzing feedback..."):
|
| 99 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
payload = {
|
| 101 |
"text": st.session_state.review,
|
| 102 |
-
"model": "distilbert-base-uncased-finetuned-sst-2-english"
|
| 103 |
"industry": industry,
|
| 104 |
"product_category": product_category,
|
| 105 |
"verbosity": verbosity,
|
| 106 |
"aspects": use_aspects,
|
| 107 |
"intelligence": st.session_state.intelligence_mode
|
| 108 |
}
|
| 109 |
-
headers = {"x-api-key": api_token}
|
| 110 |
res = requests.post(f"{backend_url}/analyze/", json=payload, headers=headers)
|
| 111 |
if res.ok:
|
| 112 |
st.session_state.last_response = res.json()
|
|
@@ -178,6 +186,7 @@ with tab1:
|
|
| 178 |
except Exception as e:
|
| 179 |
st.error(f"Trend error: {e}")
|
| 180 |
|
|
|
|
| 181 |
# === BULK REVIEW ANALYSIS ===
|
| 182 |
with tab2:
|
| 183 |
st.title("π Bulk Feedback Analysis")
|
|
|
|
| 76 |
with tab1:
|
| 77 |
st.title("π ChurnSight AI β Product Feedback Assistant")
|
| 78 |
st.markdown("Analyze feedback to detect churn risk, extract pain points, and support product decisions.")
|
| 79 |
+
|
| 80 |
review = st.text_area("π Enter Customer Feedback", value=st.session_state.review, height=180)
|
| 81 |
st.session_state.review = review
|
| 82 |
|
| 83 |
+
analyze = False # β
define outside
|
| 84 |
col1, col2, col3 = st.columns(3)
|
| 85 |
+
with col1:
|
| 86 |
+
analyze = st.button("π Analyze")
|
| 87 |
+
with col2:
|
| 88 |
+
if st.button("π² Example"):
|
| 89 |
+
st.session_state.review = (
|
| 90 |
+
"The app crashes every time I try to checkout. It's so slow and unresponsive. "
|
| 91 |
+
"Customer support never replied. I'm switching to another brand."
|
| 92 |
+
)
|
| 93 |
+
st.session_state.trigger_example_analysis = True
|
| 94 |
+
st.rerun()
|
| 95 |
+
with col3:
|
| 96 |
+
if st.button("π§Ή Clear"):
|
| 97 |
+
for key in ["review", "last_response", "followup_answer"]:
|
| 98 |
+
st.session_state[key] = ""
|
| 99 |
+
st.rerun()
|
| 100 |
|
| 101 |
if st.session_state.review and (analyze or st.session_state.trigger_example_analysis):
|
| 102 |
with st.spinner("Analyzing feedback..."):
|
| 103 |
try:
|
| 104 |
+
model_used = (
|
| 105 |
+
None if sentiment_model == "Auto-detect"
|
| 106 |
+
else sentiment_model
|
| 107 |
+
)
|
| 108 |
payload = {
|
| 109 |
"text": st.session_state.review,
|
| 110 |
+
"model": model_used or "distilbert-base-uncased-finetuned-sst-2-english",
|
| 111 |
"industry": industry,
|
| 112 |
"product_category": product_category,
|
| 113 |
"verbosity": verbosity,
|
| 114 |
"aspects": use_aspects,
|
| 115 |
"intelligence": st.session_state.intelligence_mode
|
| 116 |
}
|
| 117 |
+
headers = {"x-api-key": st.session_state.get("api_token", "my-secret-key")}
|
| 118 |
res = requests.post(f"{backend_url}/analyze/", json=payload, headers=headers)
|
| 119 |
if res.ok:
|
| 120 |
st.session_state.last_response = res.json()
|
|
|
|
| 186 |
except Exception as e:
|
| 187 |
st.error(f"Trend error: {e}")
|
| 188 |
|
| 189 |
+
|
| 190 |
# === BULK REVIEW ANALYSIS ===
|
| 191 |
with tab2:
|
| 192 |
st.title("π Bulk Feedback Analysis")
|