# app.py import streamlit as st st.set_page_config( page_title="MindLens – Your Reflection Companion", page_icon="🧠", layout="centered", ) # Now safe to import the rest import textwrap from insight_engine import InsightEngine MODEL_CLASSIFIER = None MODEL_SUMMARIZER = None # optional: "sshleifer/distilbart-cnn-12-6" or None # Create engine , cached resource so it doesn't re-load on every rerun @st.cache_resource def get_engine(): return InsightEngine(classifier_model=MODEL_CLASSIFIER, summarizer_model=MODEL_SUMMARIZER) engine = get_engine() # --- Page UI --- st.markdown( """ """, unsafe_allow_html=True ) st.markdown("
", unsafe_allow_html=True) st.markdown("
🧠 MindLens — Your Reflection Companion
", unsafe_allow_html=True) st.markdown("
Write how you're feeling and get a short insight, gentle reflection prompts and micro-actions.
", unsafe_allow_html=True) with st.form("reflection_form"): text = st.text_area("💬 Write your thoughts:", height=220, placeholder="Example: I've been working hard and feel tired but also proud...", key="input_text") submitted = st.form_submit_button("✨ Analyze My Thoughts") # small note about model availability if engine.classifier is None and engine.zero_shot is None: st.warning("Model classifiers not found — MindLens will use lightweight heuristics. (Upload a fine-tuned model for better accuracy.)") # Analyze when user submits if submitted: # ensure text not empty if not text or not text.strip(): st.error("Please write a few sentences so MindLens can analyze them.") else: with st.spinner("Analyzing — one moment..."): result = engine.analyze(text) # Render output in a clean white card st.markdown("
", unsafe_allow_html=True) st.markdown("
🔮
Summary
", unsafe_allow_html=True) st.markdown(f"
{result.get('summary','')}
", unsafe_allow_html=True) mood = result.get("mood", "neutral") mood_conf = result.get("mood_confidence", 0.0) balance = result.get("balance_score", "N/A") st.markdown("
", unsafe_allow_html=True) st.markdown(f"
Mood: {mood.title()}
" f"
Confidence: {round(mood_conf*100,1) if isinstance(mood_conf,float) else mood_conf}%
" f"
Balance Score: {balance}/100
", unsafe_allow_html=True) # Reflection prompts st.markdown("
", unsafe_allow_html=True) st.markdown("### 🪞 Reflection prompts") for p in result.get("reflection_prompts", []): st.markdown(f"- {p}") st.markdown("### 🌱 Micro-actions") for a in result.get("micro_actions", []): st.markdown(f"- {a}") st.markdown("### 💡 Practical suggestions (concise)") for s in result.get("suggestions", []): st.markdown(f"- {s}") st.markdown("
", unsafe_allow_html=True) # # helpful note st.markdown("
Note: states like happines/joy may show as Optimist/neutral.
", unsafe_allow_html=True)