churnsight-ai / frontend.py
Hasitha16's picture
Update frontend.py
939ac52 verified
raw
history blame
1.84 kB
import streamlit as st
import requests
from gtts import gTTS
import base64
from io import BytesIO
st.set_page_config(page_title="NeuroPulse AI", page_icon="🧠", layout="wide")
if "review" not in st.session_state:
st.session_state.review = ""
if "dark_mode" not in st.session_state:
st.session_state.dark_mode = False
if st.session_state.dark_mode:
st.markdown("""<style>body { background-color: #111; color: white; }</style>""", unsafe_allow_html=True)
with st.sidebar:
st.title("βš™οΈ Settings")
st.session_state.dark_mode = st.toggle("πŸŒ™ Dark Mode", value=st.session_state.dark_mode)
api_key = st.text_input("πŸ” API Key", type="password")
backend_url = st.text_input("🌐 Backend URL", value="http://localhost:8000")
st.title("🧠 NeuroPulse AI – Multimodal Review Analyzer")
review = st.text_area("πŸ“ Enter Review", value=st.session_state.review, height=150)
if st.button("πŸ” Analyze", use_container_width=True):
if not api_key:
st.error("⚠️ Please enter API key.")
elif len(review.split()) < 10:
st.warning("πŸ“ Minimum 10 words required.")
else:
with st.spinner("Processing..."):
try:
payload = {"text": review}
headers = {"x-api-key": api_key}
res = requests.post(f"{backend_url}/analyze/", json=payload, headers=headers)
if res.status_code == 200:
data = res.json()
st.success("βœ… Analysis Successful")
st.info(f"πŸ“Œ Summary: {data['summary']}")
st.metric("πŸ“Š Sentiment", data["sentiment"]["label"])
else:
st.error(f"❌ API Error: {res.status_code} - {res.text}")
except Exception as e:
st.error(f"🚫 Exception: {e}")