import time import requests import streamlit as st from shared import MAX_FILES, analyze_payload, count_files, detect_perspective_payload st.set_page_config(page_title="Velra | AI Relationship Intelligence", layout="centered", initial_sidebar_state="collapsed") st.markdown( """ """, unsafe_allow_html=True, ) # Background Orbs @st.dialog("Help Velra understand the emotional perspective") def clarification_dialog(): st.markdown("

Some conversations can be emotionally complex. A little context helps Velra give more accurate insights.

", unsafe_allow_html=True) user_perspective = st.radio("Which side feels closest to your perspective?", ["Left side", "Right side", "Mixed / unsure"]) emotional_goal = st.selectbox("What are you hoping Velra helps you understand?", [ "Do they actually care?", "Why are they emotionally distant?", "Are we emotionally compatible?", "Am I overthinking this?", "Is this relationship healthy?", "I just want clarity", "Other" ]) if st.button("Continue Analysis ✨", use_container_width=True): st.session_state.clarification_data = { "user_perspective": user_perspective, "emotional_goal": emotional_goal } st.session_state.show_dialog = False st.session_state.run_analysis = True st.rerun() st.markdown('
', unsafe_allow_html=True) # Navigation st.markdown( """
Relationship Intelligence
""", unsafe_allow_html=True ) st.markdown( """

See what they
REALLY mean.

Velra decodes emotional patterns, mixed signals, attachment dynamics, and relationship psychology. Upload your chat or explain the situation.

""", unsafe_allow_html=True ) col1, col2, col3 = st.columns([1, 2, 1]) default_chat = st.session_state.get("draft_chat", "") default_feelings = st.session_state.get("draft_feelings", "") with st.form("analysis_form", clear_on_submit=False): chat = st.text_area( "Conversation context", value=default_chat, placeholder="Paste messages, snippets, or simply explain what happened...", ) feelings = st.text_input( "Your intuition", value=default_feelings, placeholder="Describe this relationship briefly... Who is this person to you? What are you confused about?", ) uploaded_files = st.file_uploader( "Screenshots (Drag and Drop supported)", accept_multiple_files=True, help=f"Upload up to {MAX_FILES} chat screenshots.", ) same_person = st.checkbox("Yes, all screenshots are from the same person/conversation", value=False) submitted = st.form_submit_button("Analyze Connection ✨", use_container_width=True) if submitted: if count_files(uploaded_files) > MAX_FILES: st.error(f"Please limit uploads to {MAX_FILES} images.") elif count_files(uploaded_files) > 0 and not chat.strip() and not feelings.strip(): st.error("Since you only uploaded images without a chat transcript, your feelings/intuition are REQUIRED.") elif count_files(uploaded_files) > 0 and not same_person: st.error("Please confirm that all screenshots are from the same person/conversation.") else: with st.spinner("Detecting perspective..."): try: res = detect_perspective_payload(chat, feelings, uploaded_files) needs_clar = res.get("needs_clarification", False) or res.get("confidence", 1.0) < 0.75 or res.get("possible_multiple_conversations", False) except Exception as e: needs_clar = True if needs_clar: st.session_state.show_dialog = True st.session_state.pending_chat = chat st.session_state.pending_feelings = feelings st.session_state.pending_files = uploaded_files st.rerun() else: st.session_state.run_analysis = True st.session_state.clarification_data = {} st.session_state.pending_chat = chat st.session_state.pending_feelings = feelings st.session_state.pending_files = uploaded_files st.rerun() if st.session_state.get("show_dialog"): clarification_dialog() if st.session_state.get("run_analysis"): loading_placeholder = st.empty() loading_html = """
Decoding emotional signals...
Reading conversational tone
""" loading_placeholder.markdown(loading_html, unsafe_allow_html=True) stages = [ "Detecting attachment signals...", "Measuring emotional consistency...", "Identifying mixed signals...", "Predicting relationship trajectory..." ] for stage in stages: time.sleep(0.8) loading_placeholder.markdown( f"""
🧠
Analyzing dynamics...
{stage}
""", unsafe_allow_html=True ) try: c_data = st.session_state.get("clarification_data", {}) # Use values from session state to avoid empty inputs after rerun analysis_chat = st.session_state.get("pending_chat", "") analysis_feelings = st.session_state.get("pending_feelings", "") analysis_files = st.session_state.get("pending_files", []) payload = analyze_payload( analysis_chat, analysis_feelings, analysis_files, user_perspective=c_data.get("user_perspective", ""), emotional_goal=c_data.get("emotional_goal", ""), conversation_consistency=c_data.get("conversation_consistency", "") ) st.session_state.run_analysis = False st.session_state.show_dialog = False st.session_state["analysis_payload"] = payload.get("analysis", {}) st.session_state["analysis_raw"] = payload.get("raw", {}) # Save the actual text used for analysis to drafts st.session_state["draft_chat"] = analysis_chat st.session_state["draft_feelings"] = analysis_feelings loading_placeholder.empty() st.switch_page("pages/results.py") except Exception as e: loading_placeholder.empty() st.error(f"Velra encountered an issue connecting to the engine. Details: {e}")