Spaces:
Running
Running
Update frontend.py
Browse files- frontend.py +33 -0
frontend.py
CHANGED
|
@@ -6,7 +6,13 @@ import base64
|
|
| 6 |
from io import BytesIO
|
| 7 |
import os
|
| 8 |
import plotly.express as px
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
st.set_page_config(page_title="ChurnSight AI", page_icon="π§ ", layout="wide")
|
| 11 |
|
| 12 |
if os.path.exists("logo.png"):
|
|
@@ -145,6 +151,19 @@ with tab1:
|
|
| 145 |
|
| 146 |
if "pain_points" in data and data["pain_points"]:
|
| 147 |
st.error("π Pain Points: " + ", ".join(data["pain_points"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
st.subheader("π Audio Summary")
|
| 150 |
audio = speak(data["summary"], lang=voice_lang)
|
|
@@ -200,3 +219,17 @@ with tab1:
|
|
| 200 |
if st.session_state.followup_answer:
|
| 201 |
st.subheader("β
Answer")
|
| 202 |
st.success(st.session_state.followup_answer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from io import BytesIO
|
| 7 |
import os
|
| 8 |
import plotly.express as px
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
import uuid
|
| 11 |
|
| 12 |
+
# Simulated in-memory storage for churn log (replace with a database or file in production)
|
| 13 |
+
if "churn_log" not in st.session_state:
|
| 14 |
+
st.session_state.churn_log = []
|
| 15 |
+
|
| 16 |
st.set_page_config(page_title="ChurnSight AI", page_icon="π§ ", layout="wide")
|
| 17 |
|
| 18 |
if os.path.exists("logo.png"):
|
|
|
|
| 151 |
|
| 152 |
if "pain_points" in data and data["pain_points"]:
|
| 153 |
st.error("π Pain Points: " + ", ".join(data["pain_points"]))
|
| 154 |
+
# Add churn risk to session log
|
| 155 |
+
try:
|
| 156 |
+
st.session_state.churn_log.append({
|
| 157 |
+
"timestamp": datetime.now(),
|
| 158 |
+
"product": data.get("product_category", "General"),
|
| 159 |
+
"churn_risk": data.get("churn_risk", "Unknown"),
|
| 160 |
+
"session_id": str(uuid.uuid4())
|
| 161 |
+
})
|
| 162 |
+
# Keep log lightweight
|
| 163 |
+
if len(st.session_state.churn_log) > 1000:
|
| 164 |
+
st.session_state.churn_log = st.session_state.churn_log[-1000:]
|
| 165 |
+
except Exception as e:
|
| 166 |
+
st.warning(f"π§ͺ Logging failed: {e}")
|
| 167 |
|
| 168 |
st.subheader("π Audio Summary")
|
| 169 |
audio = speak(data["summary"], lang=voice_lang)
|
|
|
|
| 219 |
if st.session_state.followup_answer:
|
| 220 |
st.subheader("β
Answer")
|
| 221 |
st.success(st.session_state.followup_answer)
|
| 222 |
+
# π Show churn trend chart (optional)
|
| 223 |
+
if st.checkbox("π Show Churn Risk Trends", value=False):
|
| 224 |
+
try:
|
| 225 |
+
df = pd.DataFrame(st.session_state.churn_log)
|
| 226 |
+
df["date"] = pd.to_datetime(df["timestamp"]).dt.date
|
| 227 |
+
trend = df.groupby(["date", "churn_risk"]).size().unstack(fill_value=0).reset_index()
|
| 228 |
+
|
| 229 |
+
st.markdown("#### π
Daily Churn Trend")
|
| 230 |
+
fig = px.bar(trend, x="date", y=["High Risk", "Low Risk"], barmode="group", title="Daily Churn Risk Distribution")
|
| 231 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 232 |
+
|
| 233 |
+
st.download_button("β¬οΈ Export Trend CSV", trend.to_csv(index=False), "churn_trend.csv", mime="text/csv")
|
| 234 |
+
except Exception as e:
|
| 235 |
+
st.error(f"β Failed to generate trend: {e}")
|