Hasitha16 commited on
Commit
4ce1c62
Β·
verified Β·
1 Parent(s): c4b1956

Update frontend.py

Browse files
Files changed (1) hide show
  1. 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
- if col1.button("πŸ” Analyze"):
84
- st.session_state.trigger_example_analysis = False
85
- if col2.button("🎲 Example"):
86
- st.session_state.review = (
87
- "The app crashes every time I try to checkout. It's so slow and unresponsive. "
88
- "Customer support never replied. I'm switching to another brand."
89
- )
90
- st.session_state.trigger_example_analysis = True
91
- st.rerun()
92
- if col3.button("🧹 Clear"):
93
- for key in ["review", "last_response", "followup_answer"]:
94
- st.session_state[key] = ""
95
- st.rerun()
 
 
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" if sentiment_model == "Auto-detect" else sentiment_model,
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")