Spaces:
Sleeping
Sleeping
Update frontend.py
Browse files- frontend.py +17 -7
frontend.py
CHANGED
|
@@ -23,7 +23,10 @@ defaults = {
|
|
| 23 |
"intelligence_mode": True,
|
| 24 |
"trigger_example_analysis": False,
|
| 25 |
"last_response": None,
|
| 26 |
-
"followup_answer": None
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
for k, v in defaults.items():
|
| 29 |
if k not in st.session_state:
|
|
@@ -53,8 +56,8 @@ with st.sidebar:
|
|
| 53 |
sentiment_model = st.selectbox("π Sentiment Model", ["Auto-detect", "distilbert-base-uncased-finetuned-sst-2-english"])
|
| 54 |
industry = st.selectbox("π Industry", ["Auto-detect", "Generic", "E-commerce", "Healthcare", "Education"])
|
| 55 |
product_category = st.selectbox("π§© Product Category", ["Auto-detect", "General", "Mobile Devices", "Laptops"])
|
| 56 |
-
use_aspects = st.checkbox("π Detect Pain Points")
|
| 57 |
-
use_explain_bulk = st.checkbox("π§ Generate PM Insight (Bulk)")
|
| 58 |
verbosity = st.radio("π£οΈ Response Style", ["Brief", "Detailed"])
|
| 59 |
|
| 60 |
tab1, tab2 = st.tabs(["π§ Analyze Review", "π Bulk Reviews"])
|
|
@@ -90,12 +93,13 @@ with tab1:
|
|
| 90 |
try:
|
| 91 |
model_used = None if sentiment_model == "Auto-detect" else sentiment_model
|
| 92 |
payload = {
|
|
|
|
| 93 |
"text": st.session_state.review,
|
| 94 |
"model": model_used or "distilbert-base-uncased-finetuned-sst-2-english",
|
| 95 |
"industry": industry,
|
| 96 |
"product_category": product_category,
|
| 97 |
"verbosity": verbosity,
|
| 98 |
-
"aspects": use_aspects,
|
| 99 |
"intelligence": st.session_state.get("intelligence_mode", False)
|
| 100 |
}
|
| 101 |
headers = {"x-api-key": st.session_state.get("api_token", "my-secret-key")}
|
|
@@ -123,8 +127,12 @@ with tab1:
|
|
| 123 |
risk = data["churn_risk"]
|
| 124 |
color = "π΄" if risk == "High Risk" else "π’"
|
| 125 |
st.metric("π¨ Churn Risk", f"{color} {risk}")
|
| 126 |
-
if
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
try:
|
| 130 |
st.session_state.churn_log.append({
|
|
@@ -197,8 +205,10 @@ with tab2:
|
|
| 197 |
"industry": None,
|
| 198 |
"product_category": None,
|
| 199 |
"device": None,
|
| 200 |
-
"aspects": use_aspects,
|
| 201 |
"intelligence": st.session_state.intelligence_mode
|
|
|
|
|
|
|
| 202 |
}
|
| 203 |
try:
|
| 204 |
res = requests.post(f"{backend_url}/bulk/?token={api_token}", json=payload)
|
|
|
|
| 23 |
"intelligence_mode": True,
|
| 24 |
"trigger_example_analysis": False,
|
| 25 |
"last_response": None,
|
| 26 |
+
"followup_answer": None,
|
| 27 |
+
"use_aspects": False,
|
| 28 |
+
"use_explain_bulk": False
|
| 29 |
+
|
| 30 |
}
|
| 31 |
for k, v in defaults.items():
|
| 32 |
if k not in st.session_state:
|
|
|
|
| 56 |
sentiment_model = st.selectbox("π Sentiment Model", ["Auto-detect", "distilbert-base-uncased-finetuned-sst-2-english"])
|
| 57 |
industry = st.selectbox("π Industry", ["Auto-detect", "Generic", "E-commerce", "Healthcare", "Education"])
|
| 58 |
product_category = st.selectbox("π§© Product Category", ["Auto-detect", "General", "Mobile Devices", "Laptops"])
|
| 59 |
+
st.session_state.use_aspects = st.checkbox("π Detect Pain Points", value=st.session_state.get("use_aspects", False))
|
| 60 |
+
st.session_state.use_explain_bulk = st.checkbox("π§ Generate PM Insight (Bulk)", value=st.session_state.get("use_explain_bulk", False))
|
| 61 |
verbosity = st.radio("π£οΈ Response Style", ["Brief", "Detailed"])
|
| 62 |
|
| 63 |
tab1, tab2 = st.tabs(["π§ Analyze Review", "π Bulk Reviews"])
|
|
|
|
| 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,
|
| 100 |
"product_category": product_category,
|
| 101 |
"verbosity": verbosity,
|
| 102 |
+
"aspects": st.session_state.use_aspects,
|
| 103 |
"intelligence": st.session_state.get("intelligence_mode", False)
|
| 104 |
}
|
| 105 |
headers = {"x-api-key": st.session_state.get("api_token", "my-secret-key")}
|
|
|
|
| 127 |
risk = data["churn_risk"]
|
| 128 |
color = "π΄" if risk == "High Risk" else "π’"
|
| 129 |
st.metric("π¨ Churn Risk", f"{color} {risk}")
|
| 130 |
+
if st.session_state.use_aspects:
|
| 131 |
+
if data.get("pain_points"):
|
| 132 |
+
st.error("π Pain Points: " + ", ".join(data["pain_points"]))
|
| 133 |
+
else:
|
| 134 |
+
st.info("β
No specific pain points were detected.")
|
| 135 |
+
|
| 136 |
|
| 137 |
try:
|
| 138 |
st.session_state.churn_log.append({
|
|
|
|
| 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": st.session_state.use_explain_bulk
|
| 211 |
+
|
| 212 |
}
|
| 213 |
try:
|
| 214 |
res = requests.post(f"{backend_url}/bulk/?token={api_token}", json=payload)
|