Update app.py
Browse files
app.py
CHANGED
|
@@ -8,136 +8,181 @@ import os
|
|
| 8 |
@st.cache_resource
|
| 9 |
def get_help_agent():
|
| 10 |
from transformers import pipeline
|
| 11 |
-
# Using BlenderBot 400M Distill as the public conversational model
|
| 12 |
return pipeline("conversational", model="facebook/blenderbot-400M-distill")
|
| 13 |
|
| 14 |
-
# Custom CSS
|
| 15 |
def inject_custom_css():
|
| 16 |
st.markdown("""
|
| 17 |
<style>
|
| 18 |
-
|
| 19 |
-
@import url('https://
|
| 20 |
-
|
| 21 |
-
html, body {
|
| 22 |
-
background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
|
| 23 |
-
color: #333;
|
| 24 |
-
margin: 0;
|
| 25 |
-
padding: 0;
|
| 26 |
-
height: 100%;
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
* {
|
| 30 |
-
font-family: '
|
| 31 |
}
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
.title {
|
| 34 |
-
font-size:
|
| 35 |
-
font-weight:
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
text-align: center;
|
| 38 |
-
margin:
|
|
|
|
| 39 |
}
|
| 40 |
-
|
| 41 |
.subtitle {
|
| 42 |
-
font-size: 1.
|
| 43 |
text-align: center;
|
| 44 |
-
color: #
|
| 45 |
-
margin-bottom:
|
|
|
|
| 46 |
}
|
| 47 |
-
|
| 48 |
-
/* UPDATED: Improved question box with subtle border-radius & shadow */
|
| 49 |
.question-box {
|
| 50 |
-
background:
|
| 51 |
-
border-radius:
|
| 52 |
padding: 2rem;
|
| 53 |
-
margin: 1.5rem
|
| 54 |
-
box-shadow: 0
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
}
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
border-radius: 12px !important;
|
| 62 |
-
padding: 0.5rem 1.5rem !important;
|
| 63 |
-
font-weight: 600 !important;
|
| 64 |
-
margin: 0.5rem !important;
|
| 65 |
-
border: none;
|
| 66 |
-
cursor: pointer;
|
| 67 |
-
transition: background-color 0.3s ease, transform 0.2s ease;
|
| 68 |
}
|
| 69 |
-
|
| 70 |
-
.
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|
| 73 |
-
|
| 74 |
-
.
|
| 75 |
-
background:
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
background: #
|
| 81 |
color: white !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
.final-reveal {
|
| 86 |
-
animation:
|
| 87 |
-
font-size: 2.
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
text-align: center;
|
| 90 |
margin: 2rem 0;
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
-
|
| 94 |
-
@keyframes
|
| 95 |
-
|
| 96 |
-
|
| 97 |
}
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
top: 0;
|
| 103 |
-
left: 0;
|
| 104 |
-
width: 100%;
|
| 105 |
-
height: 100%;
|
| 106 |
-
pointer-events: none;
|
| 107 |
-
z-index: 1000;
|
| 108 |
}
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
}
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
-
|
| 124 |
</style>
|
| 125 |
""", unsafe_allow_html=True)
|
| 126 |
|
| 127 |
-
# Confetti animation
|
| 128 |
def show_confetti():
|
| 129 |
html("""
|
| 130 |
<canvas id="confetti-canvas" class="confetti"></canvas>
|
| 131 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
|
| 132 |
<script>
|
| 133 |
-
const
|
| 134 |
-
const
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
</script>
|
| 142 |
""")
|
| 143 |
|
|
@@ -197,6 +242,7 @@ def ask_help_agent(query):
|
|
| 197 |
history = []
|
| 198 |
if "help_conversation" in st.session_state:
|
| 199 |
for msg in st.session_state.help_conversation:
|
|
|
|
| 200 |
history.append((msg.get("query", ""), msg.get("response", "")))
|
| 201 |
|
| 202 |
messages = [{"role": "system", "content": system_message}]
|
|
@@ -222,12 +268,12 @@ def ask_help_agent(query):
|
|
| 222 |
except Exception as e:
|
| 223 |
return f"Error in help agent: {str(e)}"
|
| 224 |
|
| 225 |
-
# Main game logic
|
| 226 |
def main():
|
| 227 |
-
inject_custom_css()
|
| 228 |
|
| 229 |
st.markdown('<div class="title">KASOTI</div>', unsafe_allow_html=True)
|
| 230 |
-
st.markdown('<div class="subtitle">
|
| 231 |
|
| 232 |
if 'game_state' not in st.session_state:
|
| 233 |
st.session_state.game_state = "start"
|
|
@@ -239,21 +285,32 @@ def main():
|
|
| 239 |
st.session_state.final_guess = None
|
| 240 |
st.session_state.help_conversation = [] # separate history for help agent
|
| 241 |
|
| 242 |
-
# Start screen
|
| 243 |
if st.session_state.game_state == "start":
|
| 244 |
-
st.
|
| 245 |
-
|
| 246 |
-
<
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
<
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
with st.form("start_form"):
|
| 259 |
category_input = st.text_input("Enter category (person/place/object):").strip().lower()
|
|
@@ -274,9 +331,33 @@ def main():
|
|
| 274 |
st.session_state.game_state = "gameplay"
|
| 275 |
st.experimental_rerun()
|
| 276 |
|
| 277 |
-
# Gameplay screen
|
| 278 |
elif st.session_state.game_state == "gameplay":
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
# Check if AI made a guess
|
| 282 |
if "Final Guess:" in current_question:
|
|
@@ -284,10 +365,6 @@ def main():
|
|
| 284 |
st.session_state.game_state = "confirm_guess"
|
| 285 |
st.experimental_rerun()
|
| 286 |
|
| 287 |
-
st.markdown(f'<div class="question-box">Question {st.session_state.current_q + 1}/20:<br><br>'
|
| 288 |
-
f'<strong>{current_question}</strong></div>',
|
| 289 |
-
unsafe_allow_html=True)
|
| 290 |
-
|
| 291 |
with st.form("answer_form"):
|
| 292 |
answer_input = st.text_input("Your answer (yes/no/both):",
|
| 293 |
key=f"answer_{st.session_state.current_q}").strip().lower()
|
|
@@ -339,9 +416,20 @@ def main():
|
|
| 339 |
|
| 340 |
# Guess confirmation screen using text input response
|
| 341 |
elif st.session_state.game_state == "confirm_guess":
|
| 342 |
-
st.markdown(f'
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
with st.form("confirm_form"):
|
| 347 |
confirm_input = st.text_input("Type your answer (yes/no/both):", key="confirm_input").strip().lower()
|
|
@@ -370,13 +458,15 @@ def main():
|
|
| 370 |
st.session_state.current_q += 1
|
| 371 |
st.experimental_rerun()
|
| 372 |
|
| 373 |
-
# Result screen
|
| 374 |
elif st.session_state.game_state == "result":
|
| 375 |
if not st.session_state.final_guess:
|
|
|
|
| 376 |
qa_history = "\n".join(
|
| 377 |
[f"Q{i+1}: {q}\nA: {a}"
|
| 378 |
for i, (q, a) in enumerate(zip(st.session_state.questions, st.session_state.answers))]
|
| 379 |
)
|
|
|
|
| 380 |
final_guess = ask_llama(
|
| 381 |
[{"role": "user", "content": qa_history}],
|
| 382 |
st.session_state.category,
|
|
@@ -389,7 +479,7 @@ def main():
|
|
| 389 |
time.sleep(1)
|
| 390 |
st.markdown(f'<div class="final-reveal" style="font-size:3.5rem;color:#6C63FF;">{st.session_state.final_guess}</div>',
|
| 391 |
unsafe_allow_html=True)
|
| 392 |
-
st.markdown(f"<p style='text-align:center'>Guessed in {len(st.session_state.questions)} questions</p>",
|
| 393 |
unsafe_allow_html=True)
|
| 394 |
|
| 395 |
if st.button("Play Again", key="play_again"):
|
|
@@ -397,4 +487,4 @@ def main():
|
|
| 397 |
st.experimental_rerun()
|
| 398 |
|
| 399 |
if __name__ == "__main__":
|
| 400 |
-
main()
|
|
|
|
| 8 |
@st.cache_resource
|
| 9 |
def get_help_agent():
|
| 10 |
from transformers import pipeline
|
| 11 |
+
# Using BlenderBot 400M Distill as the public conversational model (used elsewhere)
|
| 12 |
return pipeline("conversational", model="facebook/blenderbot-400M-distill")
|
| 13 |
|
| 14 |
+
# Enhanced Custom CSS with modern design
|
| 15 |
def inject_custom_css():
|
| 16 |
st.markdown("""
|
| 17 |
<style>
|
| 18 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
| 19 |
+
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css');
|
| 20 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
* {
|
| 22 |
+
font-family: 'Inter', sans-serif;
|
| 23 |
}
|
| 24 |
+
|
| 25 |
+
body {
|
| 26 |
+
background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
.title {
|
| 30 |
+
font-size: 2.8rem !important;
|
| 31 |
+
font-weight: 800 !important;
|
| 32 |
+
background: linear-gradient(45deg, #6C63FF, #3B82F6);
|
| 33 |
+
-webkit-background-clip: text;
|
| 34 |
+
-webkit-text-fill-color: transparent;
|
| 35 |
text-align: center;
|
| 36 |
+
margin: 1rem 0;
|
| 37 |
+
letter-spacing: -1px;
|
| 38 |
}
|
| 39 |
+
|
| 40 |
.subtitle {
|
| 41 |
+
font-size: 1.1rem !important;
|
| 42 |
text-align: center;
|
| 43 |
+
color: #64748B !important;
|
| 44 |
+
margin-bottom: 2.5rem;
|
| 45 |
+
animation: fadeInSlide 1s ease;
|
| 46 |
}
|
| 47 |
+
|
|
|
|
| 48 |
.question-box {
|
| 49 |
+
background: white;
|
| 50 |
+
border-radius: 20px;
|
| 51 |
padding: 2rem;
|
| 52 |
+
margin: 1.5rem 0;
|
| 53 |
+
box-shadow: 0 10px 25px rgba(0,0,0,0.08);
|
| 54 |
+
border: 1px solid #e2e8f0;
|
| 55 |
+
position: relative;
|
| 56 |
+
transition: transform 0.2s ease;
|
| 57 |
}
|
| 58 |
+
|
| 59 |
+
.question-box:hover {
|
| 60 |
+
transform: translateY(-3px);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
+
|
| 63 |
+
.question-box::before {
|
| 64 |
+
content: "🕹️";
|
| 65 |
+
position: absolute;
|
| 66 |
+
left: -15px;
|
| 67 |
+
top: -15px;
|
| 68 |
+
background: white;
|
| 69 |
+
border-radius: 50%;
|
| 70 |
+
padding: 8px;
|
| 71 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 72 |
+
font-size: 1.2rem;
|
| 73 |
}
|
| 74 |
+
|
| 75 |
+
.input-box {
|
| 76 |
+
background: white;
|
| 77 |
+
border-radius: 12px;
|
| 78 |
+
padding: 1.5rem;
|
| 79 |
+
margin: 1rem 0;
|
| 80 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
.stTextInput input {
|
| 84 |
+
border: 2px solid #e2e8f0 !important;
|
| 85 |
+
border-radius: 10px !important;
|
| 86 |
+
padding: 12px 16px !important;
|
| 87 |
+
transition: all 0.3s ease !important;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.stTextInput input:focus {
|
| 91 |
+
border-color: #6C63FF !important;
|
| 92 |
+
box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.2) !important;
|
| 93 |
}
|
| 94 |
+
|
| 95 |
+
button {
|
| 96 |
+
background: linear-gradient(45deg, #6C63FF, #3B82F6) !important;
|
| 97 |
color: white !important;
|
| 98 |
+
border: none !important;
|
| 99 |
+
border-radius: 10px !important;
|
| 100 |
+
padding: 12px 24px !important;
|
| 101 |
+
font-weight: 600 !important;
|
| 102 |
+
transition: all 0.3s ease !important;
|
| 103 |
}
|
| 104 |
+
|
| 105 |
+
button:hover {
|
| 106 |
+
transform: translateY(-2px);
|
| 107 |
+
box-shadow: 0 5px 15px rgba(108, 99, 255, 0.3) !important;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
.final-reveal {
|
| 111 |
+
animation: fadeInUp 1s ease;
|
| 112 |
+
font-size: 2.8rem;
|
| 113 |
+
background: linear-gradient(45deg, #6C63FF, #3B82F6);
|
| 114 |
+
-webkit-background-clip: text;
|
| 115 |
+
-webkit-text-fill-color: transparent;
|
| 116 |
text-align: center;
|
| 117 |
margin: 2rem 0;
|
| 118 |
+
font-weight: 800;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.help-chat {
|
| 122 |
+
background: rgba(255,255,255,0.9);
|
| 123 |
+
backdrop-filter: blur(10px);
|
| 124 |
+
border-radius: 15px;
|
| 125 |
+
padding: 1rem;
|
| 126 |
+
margin: 1rem 0;
|
| 127 |
+
box-shadow: 0 8px 30px rgba(0,0,0,0.12);
|
| 128 |
}
|
| 129 |
+
|
| 130 |
+
@keyframes fadeInSlide {
|
| 131 |
+
0% { opacity: 0; transform: translateY(20px); }
|
| 132 |
+
100% { opacity: 1; transform: translateY(0); }
|
| 133 |
}
|
| 134 |
+
|
| 135 |
+
@keyframes fadeInUp {
|
| 136 |
+
0% { opacity: 0; transform: translateY(30px); }
|
| 137 |
+
100% { opacity: 1; transform: translateY(0); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
+
|
| 140 |
+
.progress-bar {
|
| 141 |
+
height: 6px;
|
| 142 |
+
background: #e2e8f0;
|
| 143 |
+
border-radius: 3px;
|
| 144 |
+
margin: 1.5rem 0;
|
| 145 |
+
overflow: hidden;
|
| 146 |
}
|
| 147 |
+
|
| 148 |
+
.progress-fill {
|
| 149 |
+
height: 100%;
|
| 150 |
+
background: linear-gradient(90deg, #6C63FF, #3B82F6);
|
| 151 |
+
transition: width 0.5s ease;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.question-count {
|
| 155 |
+
color: #6C63FF;
|
| 156 |
+
font-weight: 600;
|
| 157 |
+
font-size: 0.9rem;
|
| 158 |
+
margin-bottom: 0.5rem;
|
| 159 |
}
|
|
|
|
| 160 |
</style>
|
| 161 |
""", unsafe_allow_html=True)
|
| 162 |
|
| 163 |
+
# Confetti animation (enhanced)
|
| 164 |
def show_confetti():
|
| 165 |
html("""
|
| 166 |
<canvas id="confetti-canvas" class="confetti"></canvas>
|
| 167 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
|
| 168 |
<script>
|
| 169 |
+
const count = 200;
|
| 170 |
+
const defaults = {
|
| 171 |
+
origin: { y: 0.7 },
|
| 172 |
+
zIndex: 1050
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
function fire(particleRatio, opts) {
|
| 176 |
+
confetti(Object.assign({}, defaults, opts, {
|
| 177 |
+
particleCount: Math.floor(count * particleRatio)
|
| 178 |
+
}));
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
fire(0.25, { spread: 26, startVelocity: 55 });
|
| 182 |
+
fire(0.2, { spread: 60 });
|
| 183 |
+
fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
|
| 184 |
+
fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
|
| 185 |
+
fire(0.1, { spread: 120, startVelocity: 45 });
|
| 186 |
</script>
|
| 187 |
""")
|
| 188 |
|
|
|
|
| 242 |
history = []
|
| 243 |
if "help_conversation" in st.session_state:
|
| 244 |
for msg in st.session_state.help_conversation:
|
| 245 |
+
# Each history entry is a tuple: (user query, assistant response)
|
| 246 |
history.append((msg.get("query", ""), msg.get("response", "")))
|
| 247 |
|
| 248 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 268 |
except Exception as e:
|
| 269 |
return f"Error in help agent: {str(e)}"
|
| 270 |
|
| 271 |
+
# Main game logic with enhanced UI
|
| 272 |
def main():
|
| 273 |
+
inject_custom_css()
|
| 274 |
|
| 275 |
st.markdown('<div class="title">KASOTI</div>', unsafe_allow_html=True)
|
| 276 |
+
st.markdown('<div class="subtitle">AI-Powered Guessing Game Challenge</div>', unsafe_allow_html=True)
|
| 277 |
|
| 278 |
if 'game_state' not in st.session_state:
|
| 279 |
st.session_state.game_state = "start"
|
|
|
|
| 285 |
st.session_state.final_guess = None
|
| 286 |
st.session_state.help_conversation = [] # separate history for help agent
|
| 287 |
|
| 288 |
+
# Start screen with enhanced layout
|
| 289 |
if st.session_state.game_state == "start":
|
| 290 |
+
with st.container():
|
| 291 |
+
st.markdown("""
|
| 292 |
+
<div class="question-box">
|
| 293 |
+
<h3 style="color: #6C63FF; margin-bottom: 1.5rem;">🎮 Welcome to KASOTI</h3>
|
| 294 |
+
<p style="line-height: 1.6; color: #64748B;">
|
| 295 |
+
Think of something and I'll try to guess it in 20 questions or less!<br>
|
| 296 |
+
Choose from these categories:
|
| 297 |
+
</p>
|
| 298 |
+
<div style="display: grid; gap: 1rem; margin: 2rem 0;">
|
| 299 |
+
<div style="padding: 1.5rem; background: #f8f9fa; border-radius: 12px;">
|
| 300 |
+
<h4 style="margin: 0; color: #6C63FF;">🧑 Person</h4>
|
| 301 |
+
<p style="margin: 0.5rem 0 0; color: #64748B;">Celebrity, fictional character, historical figure</p>
|
| 302 |
+
</div>
|
| 303 |
+
<div style="padding: 1.5rem; background: #f8f9fa; border-radius: 12px;">
|
| 304 |
+
<h4 style="margin: 0; color: #6C63FF;">🌍 Place</h4>
|
| 305 |
+
<p style="margin: 0.5rem 0 0; color: #64748B;">City, country, landmark, geographical location</p>
|
| 306 |
+
</div>
|
| 307 |
+
<div style="padding: 1.5rem; background: #f8f9fa; border-radius: 12px;">
|
| 308 |
+
<h4 style="margin: 0; color: #6C63FF;">🎯 Object</h4>
|
| 309 |
+
<p style="margin: 0.5rem 0 0; color: #64748B;">Everyday item, tool, vehicle, or concept</p>
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
</div>
|
| 313 |
+
""", unsafe_allow_html=True)
|
| 314 |
|
| 315 |
with st.form("start_form"):
|
| 316 |
category_input = st.text_input("Enter category (person/place/object):").strip().lower()
|
|
|
|
| 331 |
st.session_state.game_state = "gameplay"
|
| 332 |
st.experimental_rerun()
|
| 333 |
|
| 334 |
+
# Gameplay screen with progress bar
|
| 335 |
elif st.session_state.game_state == "gameplay":
|
| 336 |
+
with st.container():
|
| 337 |
+
# Add progress bar
|
| 338 |
+
progress = (st.session_state.current_q + 1) / 20
|
| 339 |
+
st.markdown(f"""
|
| 340 |
+
<div class="question-count">QUESTION {st.session_state.current_q + 1} OF 20</div>
|
| 341 |
+
<div class="progress-bar">
|
| 342 |
+
<div class="progress-fill" style="width: {progress * 100}%"></div>
|
| 343 |
+
</div>
|
| 344 |
+
""", unsafe_allow_html=True)
|
| 345 |
+
|
| 346 |
+
current_question = st.session_state.questions[st.session_state.current_q]
|
| 347 |
+
|
| 348 |
+
# Enhanced question box
|
| 349 |
+
st.markdown(f'''
|
| 350 |
+
<div class="question-box">
|
| 351 |
+
<div style="display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem;">
|
| 352 |
+
<div style="background: #6C63FF; width: 40px; height: 40px; border-radius: 50%;
|
| 353 |
+
display: flex; align-items: center; justify-content: center; color: white;">
|
| 354 |
+
<i class="fas fa-robot"></i>
|
| 355 |
+
</div>
|
| 356 |
+
<h3 style="margin: 0; color: #1E293B;">AI Question</h3>
|
| 357 |
+
</div>
|
| 358 |
+
<p style="font-size: 1.1rem; line-height: 1.6; color: #1E293B;">{current_question}</p>
|
| 359 |
+
</div>
|
| 360 |
+
''', unsafe_allow_html=True)
|
| 361 |
|
| 362 |
# Check if AI made a guess
|
| 363 |
if "Final Guess:" in current_question:
|
|
|
|
| 365 |
st.session_state.game_state = "confirm_guess"
|
| 366 |
st.experimental_rerun()
|
| 367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
with st.form("answer_form"):
|
| 369 |
answer_input = st.text_input("Your answer (yes/no/both):",
|
| 370 |
key=f"answer_{st.session_state.current_q}").strip().lower()
|
|
|
|
| 416 |
|
| 417 |
# Guess confirmation screen using text input response
|
| 418 |
elif st.session_state.game_state == "confirm_guess":
|
| 419 |
+
st.markdown(f'''
|
| 420 |
+
<div class="question-box">
|
| 421 |
+
<div style="display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem;">
|
| 422 |
+
<div style="background: #6C63FF; width: 40px; height: 40px; border-radius: 50%;
|
| 423 |
+
display: flex; align-items: center; justify-content: center; color: white;">
|
| 424 |
+
<i class="fas fa-lightbulb"></i>
|
| 425 |
+
</div>
|
| 426 |
+
<h3 style="margin: 0; color: #1E293B;">AI's Final Guess</h3>
|
| 427 |
+
</div>
|
| 428 |
+
<p style="font-size: 1.2rem; line-height: 1.6; color: #1E293B;">
|
| 429 |
+
Is it <strong style="color: #6C63FF;">{st.session_state.final_guess}</strong>?
|
| 430 |
+
</p>
|
| 431 |
+
</div>
|
| 432 |
+
''', unsafe_allow_html=True)
|
| 433 |
|
| 434 |
with st.form("confirm_form"):
|
| 435 |
confirm_input = st.text_input("Type your answer (yes/no/both):", key="confirm_input").strip().lower()
|
|
|
|
| 458 |
st.session_state.current_q += 1
|
| 459 |
st.experimental_rerun()
|
| 460 |
|
| 461 |
+
# Result screen with enhanced celebration
|
| 462 |
elif st.session_state.game_state == "result":
|
| 463 |
if not st.session_state.final_guess:
|
| 464 |
+
# Generate final guess if not already made
|
| 465 |
qa_history = "\n".join(
|
| 466 |
[f"Q{i+1}: {q}\nA: {a}"
|
| 467 |
for i, (q, a) in enumerate(zip(st.session_state.questions, st.session_state.answers))]
|
| 468 |
)
|
| 469 |
+
|
| 470 |
final_guess = ask_llama(
|
| 471 |
[{"role": "user", "content": qa_history}],
|
| 472 |
st.session_state.category,
|
|
|
|
| 479 |
time.sleep(1)
|
| 480 |
st.markdown(f'<div class="final-reveal" style="font-size:3.5rem;color:#6C63FF;">{st.session_state.final_guess}</div>',
|
| 481 |
unsafe_allow_html=True)
|
| 482 |
+
st.markdown(f"<p style='text-align:center; color:#64748B;'>Guessed in {len(st.session_state.questions)} questions</p>",
|
| 483 |
unsafe_allow_html=True)
|
| 484 |
|
| 485 |
if st.button("Play Again", key="play_again"):
|
|
|
|
| 487 |
st.experimental_rerun()
|
| 488 |
|
| 489 |
if __name__ == "__main__":
|
| 490 |
+
main()
|