Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,12 @@
|
|
1 |
-
import random
|
2 |
import streamlit as st
|
|
|
3 |
from sentence_transformers import SentenceTransformer, util
|
4 |
from ensemble import get_ensembler
|
5 |
-
from quiz_engine import run_quiz_step, generate_tarot_card_summary, generate_reflection_and_prompt
|
6 |
from vibe_mapper import get_emojis_from_emotions
|
7 |
-
import streamlit.components.v1 as components
|
8 |
-
from quiz_engine import QUESTION_BANK
|
9 |
-
|
10 |
|
11 |
-
#
|
12 |
if "quiz_started" not in st.session_state:
|
13 |
st.session_state.quiz_started = False
|
14 |
if "question_index" not in st.session_state:
|
@@ -20,7 +18,7 @@ if "reflections" not in st.session_state:
|
|
20 |
if "show_final" not in st.session_state:
|
21 |
st.session_state.show_final = False
|
22 |
|
23 |
-
# ๐จ
|
24 |
st.markdown("""
|
25 |
<style>
|
26 |
body {
|
@@ -42,11 +40,11 @@ st.markdown("""
|
|
42 |
</style>
|
43 |
""", unsafe_allow_html=True)
|
44 |
|
45 |
-
#
|
46 |
if not st.session_state.quiz_started:
|
47 |
st.audio("https://www.bensound.com/bensound-music/bensound-sunny.mp3", autoplay=True)
|
48 |
|
49 |
-
#
|
50 |
if not st.session_state.quiz_started:
|
51 |
components.html("""
|
52 |
<div style="text-align: center; font-size: 2em; font-family: 'Courier New', monospace; color: #d63384;">
|
@@ -83,22 +81,19 @@ if not st.session_state.quiz_started:
|
|
83 |
</script>
|
84 |
""", height=80)
|
85 |
|
86 |
-
#
|
87 |
if not st.session_state.quiz_started:
|
88 |
if st.button("Let's Begin ๐", type="primary"):
|
89 |
st.session_state.quiz_started = True
|
90 |
st.rerun()
|
91 |
st.info("๐ผ This quiz is designed to gently uncover your emotional love style.")
|
92 |
|
|
|
93 |
else:
|
94 |
-
# Typing animation for questions
|
95 |
-
if st.session_state.question_index < len(st.session_state.answers):
|
96 |
-
st.markdown(f"<div class='question-text'>{st.session_state.answers[st.session_state.question_index]['question']}</div>", unsafe_allow_html=True)
|
97 |
-
else:
|
98 |
-
run_quiz_step()
|
99 |
-
|
100 |
if st.session_state.question_index < len(QUESTION_BANK):
|
101 |
current_question = QUESTION_BANK[st.session_state.question_index]
|
|
|
|
|
102 |
components.html(f"""
|
103 |
<div style="text-align: center; font-size: 1.4em; font-family: 'Courier New', monospace; color: #ff75a0;">
|
104 |
<span id="question-typing"></span>
|
@@ -118,15 +113,41 @@ else:
|
|
118 |
</script>
|
119 |
""", height=80)
|
120 |
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
-
|
125 |
-
|
|
|
126 |
|
127 |
-
st.subheader("๐ซ Your Emotional Reflection")
|
128 |
-
for label, score in result["top_emotions"]:
|
129 |
-
st.write(f"**{label.capitalize()}**: {score:.2f}")
|
130 |
st.markdown("**Vibe Tags:** " + ", ".join(result["vibe_tags"]))
|
131 |
st.success("๐ Vibe Tags: " + ", ".join(result["vibe_tags"]))
|
132 |
|
@@ -140,7 +161,6 @@ else:
|
|
140 |
else:
|
141 |
st.success("All clear โ nothing spicy detected.")
|
142 |
|
143 |
-
# ๐ง Log All Q&A Entries
|
144 |
st.markdown("---")
|
145 |
st.subheader("๐ Your Answers Log")
|
146 |
for idx, entry in enumerate(st.session_state.answers):
|
@@ -149,7 +169,6 @@ else:
|
|
149 |
if "reflection" in entry:
|
150 |
st.markdown(f"*Reflection:* {entry['reflection']}")
|
151 |
|
152 |
-
# ๐ฎ Generate Tarot Card Summary
|
153 |
tarot_summary = generate_tarot_card_summary(st.session_state.reflections)
|
154 |
st.markdown("---")
|
155 |
st.subheader("๐ฎ Your Romantic Archetype")
|
|
|
1 |
+
import random
|
2 |
import streamlit as st
|
3 |
+
import streamlit.components.v1 as components
|
4 |
from sentence_transformers import SentenceTransformer, util
|
5 |
from ensemble import get_ensembler
|
6 |
+
from quiz_engine import run_quiz_step, generate_tarot_card_summary, generate_reflection_and_prompt, QUESTION_BANK
|
7 |
from vibe_mapper import get_emojis_from_emotions
|
|
|
|
|
|
|
8 |
|
9 |
+
# Initialize session state
|
10 |
if "quiz_started" not in st.session_state:
|
11 |
st.session_state.quiz_started = False
|
12 |
if "question_index" not in st.session_state:
|
|
|
18 |
if "show_final" not in st.session_state:
|
19 |
st.session_state.show_final = False
|
20 |
|
21 |
+
# ๐จ Styling
|
22 |
st.markdown("""
|
23 |
<style>
|
24 |
body {
|
|
|
40 |
</style>
|
41 |
""", unsafe_allow_html=True)
|
42 |
|
43 |
+
# ๐ต Background Music
|
44 |
if not st.session_state.quiz_started:
|
45 |
st.audio("https://www.bensound.com/bensound-music/bensound-sunny.mp3", autoplay=True)
|
46 |
|
47 |
+
# ๐ฌ Typing Intro
|
48 |
if not st.session_state.quiz_started:
|
49 |
components.html("""
|
50 |
<div style="text-align: center; font-size: 2em; font-family: 'Courier New', monospace; color: #d63384;">
|
|
|
81 |
</script>
|
82 |
""", height=80)
|
83 |
|
84 |
+
# ๐ง Start Quiz Button
|
85 |
if not st.session_state.quiz_started:
|
86 |
if st.button("Let's Begin ๐", type="primary"):
|
87 |
st.session_state.quiz_started = True
|
88 |
st.rerun()
|
89 |
st.info("๐ผ This quiz is designed to gently uncover your emotional love style.")
|
90 |
|
91 |
+
# ๐งฉ Quiz in Progress
|
92 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
if st.session_state.question_index < len(QUESTION_BANK):
|
94 |
current_question = QUESTION_BANK[st.session_state.question_index]
|
95 |
+
|
96 |
+
# โจ JS Typing Animation
|
97 |
components.html(f"""
|
98 |
<div style="text-align: center; font-size: 1.4em; font-family: 'Courier New', monospace; color: #ff75a0;">
|
99 |
<span id="question-typing"></span>
|
|
|
113 |
</script>
|
114 |
""", height=80)
|
115 |
|
116 |
+
# ๐ฌ Input + Emotion Detection
|
117 |
+
user_input = st.text_input("Your response", key=f"q_{st.session_state.question_index}")
|
118 |
+
|
119 |
+
if user_input and "answered" not in st.session_state:
|
120 |
+
ensembler = get_ensembler()
|
121 |
+
tone = ensembler.predict_emotion(user_input)
|
122 |
+
st.session_state.answers.append({
|
123 |
+
"question": current_question,
|
124 |
+
"response": user_input,
|
125 |
+
"tone": tone
|
126 |
+
})
|
127 |
+
st.session_state.question_index += 1
|
128 |
+
st.session_state.answered = True
|
129 |
+
st.rerun()
|
130 |
+
|
131 |
+
if "answered" in st.session_state:
|
132 |
+
del st.session_state.answered
|
133 |
+
|
134 |
+
# โ
End of Quiz: Show Final Results on Button Press
|
135 |
+
elif len(st.session_state.answers) >= len(QUESTION_BANK):
|
136 |
+
if not st.session_state.show_final:
|
137 |
+
if st.button("Reveal My Final Reflection ๐"):
|
138 |
+
st.session_state.show_final = True
|
139 |
+
st.rerun()
|
140 |
+
else:
|
141 |
+
ensembler = get_ensembler()
|
142 |
+
st.markdown("## ๐ Final Reflection")
|
143 |
+
|
144 |
+
all_text = " ".join([entry["response"] for entry in st.session_state.answers])
|
145 |
+
result = ensembler.predict_emotion(all_text)
|
146 |
|
147 |
+
st.subheader("๐ซ Your Emotional Reflection")
|
148 |
+
for label, score in result["top_emotions"]:
|
149 |
+
st.write(f"**{label.capitalize()}**: {score:.2f}")
|
150 |
|
|
|
|
|
|
|
151 |
st.markdown("**Vibe Tags:** " + ", ".join(result["vibe_tags"]))
|
152 |
st.success("๐ Vibe Tags: " + ", ".join(result["vibe_tags"]))
|
153 |
|
|
|
161 |
else:
|
162 |
st.success("All clear โ nothing spicy detected.")
|
163 |
|
|
|
164 |
st.markdown("---")
|
165 |
st.subheader("๐ Your Answers Log")
|
166 |
for idx, entry in enumerate(st.session_state.answers):
|
|
|
169 |
if "reflection" in entry:
|
170 |
st.markdown(f"*Reflection:* {entry['reflection']}")
|
171 |
|
|
|
172 |
tarot_summary = generate_tarot_card_summary(st.session_state.reflections)
|
173 |
st.markdown("---")
|
174 |
st.subheader("๐ฎ Your Romantic Archetype")
|