Update app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,104 @@ import time
|
|
3 |
import random
|
4 |
from streamlit.components.v1 import html
|
5 |
|
6 |
-
# Custom CSS
|
7 |
def inject_custom_css():
|
8 |
st.markdown("""
|
9 |
<style>
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
</style>
|
12 |
""", unsafe_allow_html=True)
|
13 |
|
14 |
-
# Confetti animation (
|
15 |
def show_confetti():
|
16 |
html("""
|
|
|
|
|
17 |
<script>
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</script>
|
20 |
""")
|
21 |
|
|
|
22 |
def main():
|
23 |
inject_custom_css()
|
24 |
|
@@ -41,14 +123,11 @@ def main():
|
|
41 |
]
|
42 |
st.session_state.current_q = 0
|
43 |
st.session_state.answers = []
|
44 |
-
st.session_state.target = "smartphone"
|
45 |
|
46 |
# Start screen
|
47 |
if st.session_state.game_state == "start":
|
48 |
-
|
49 |
-
st.image("https://i.imgur.com/7vQD0fP.png",
|
50 |
-
caption="Think of something and we'll try to guess it!",
|
51 |
-
use_column_width=True)
|
52 |
|
53 |
with st.form("start_form"):
|
54 |
category = st.radio("What are you thinking of?",
|
@@ -66,31 +145,17 @@ def main():
|
|
66 |
st.session_state.user_input = user_input
|
67 |
st.rerun()
|
68 |
|
69 |
-
# Gameplay screen
|
70 |
elif st.session_state.game_state == "gameplay":
|
71 |
col1, col2 = st.columns([1, 3])
|
72 |
with col1:
|
73 |
-
|
74 |
-
st.image("https://i.imgur.com/JnQ6Tyr.png",
|
75 |
-
width=150,
|
76 |
-
caption=f"Question {st.session_state.current_q + 1}")
|
77 |
with col2:
|
78 |
-
st.markdown(
|
79 |
-
|
80 |
-
|
81 |
-
f'<p><strong>{st.session_state.questions[st.session_state.current_q]}</strong></p>'
|
82 |
-
f'</div>',
|
83 |
-
unsafe_allow_html=True
|
84 |
-
)
|
85 |
|
86 |
-
|
87 |
-
answer = st.radio(
|
88 |
-
"Your answer:",
|
89 |
-
["Yes", "No"],
|
90 |
-
horizontal=True,
|
91 |
-
label_visibility="collapsed",
|
92 |
-
key=f"q{st.session_state.current_q}"
|
93 |
-
)
|
94 |
|
95 |
if st.button("Submit Answer", type="primary"):
|
96 |
st.session_state.answers.append(answer == "Yes")
|
@@ -105,16 +170,10 @@ def main():
|
|
105 |
show_confetti()
|
106 |
st.markdown('<div class="final-reveal">🎉 I think it\'s a...</div>', unsafe_allow_html=True)
|
107 |
time.sleep(1)
|
108 |
-
st.markdown(
|
109 |
-
|
110 |
-
f'{st.session_state.target.upper()}'
|
111 |
-
f'</div>',
|
112 |
-
unsafe_allow_html=True
|
113 |
-
)
|
114 |
|
115 |
-
st.image("https://
|
116 |
-
caption="Congratulations!",
|
117 |
-
use_column_width=True)
|
118 |
|
119 |
if st.button("Play Again", key="play_again"):
|
120 |
st.session_state.clear()
|
|
|
3 |
import random
|
4 |
from streamlit.components.v1 import html
|
5 |
|
6 |
+
# Custom CSS for professional look
|
7 |
def inject_custom_css():
|
8 |
st.markdown("""
|
9 |
<style>
|
10 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');
|
11 |
+
|
12 |
+
* {
|
13 |
+
font-family: 'Poppins', sans-serif;
|
14 |
+
}
|
15 |
+
|
16 |
+
.title {
|
17 |
+
font-size: 3rem !important;
|
18 |
+
font-weight: 700 !important;
|
19 |
+
color: #6C63FF !important;
|
20 |
+
text-align: center;
|
21 |
+
margin-bottom: 0.5rem;
|
22 |
+
}
|
23 |
+
|
24 |
+
.subtitle {
|
25 |
+
font-size: 1.2rem !important;
|
26 |
+
text-align: center;
|
27 |
+
color: #666 !important;
|
28 |
+
margin-bottom: 2rem;
|
29 |
+
}
|
30 |
+
|
31 |
+
.question-box {
|
32 |
+
background: #F8F9FA;
|
33 |
+
border-radius: 15px;
|
34 |
+
padding: 2rem;
|
35 |
+
margin: 1.5rem 0;
|
36 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
37 |
+
color: black;
|
38 |
+
}
|
39 |
+
|
40 |
+
.answer-btn {
|
41 |
+
border-radius: 12px !important;
|
42 |
+
padding: 0.5rem 1.5rem !important;
|
43 |
+
font-weight: 600 !important;
|
44 |
+
margin: 0.5rem !important;
|
45 |
+
}
|
46 |
+
|
47 |
+
.yes-btn {
|
48 |
+
background: #6C63FF !important;
|
49 |
+
color: white !important;
|
50 |
+
}
|
51 |
+
|
52 |
+
.no-btn {
|
53 |
+
background: #FF6B6B !important;
|
54 |
+
color: white !important;
|
55 |
+
}
|
56 |
+
|
57 |
+
.final-reveal {
|
58 |
+
animation: fadeIn 2s;
|
59 |
+
font-size: 2.5rem;
|
60 |
+
color: #6C63FF;
|
61 |
+
text-align: center;
|
62 |
+
margin: 2rem 0;
|
63 |
+
}
|
64 |
+
|
65 |
+
@keyframes fadeIn {
|
66 |
+
from { opacity: 0; }
|
67 |
+
to { opacity: 1; }
|
68 |
+
}
|
69 |
+
|
70 |
+
.confetti {
|
71 |
+
position: fixed;
|
72 |
+
top: 0;
|
73 |
+
left: 0;
|
74 |
+
width: 100%;
|
75 |
+
height: 100%;
|
76 |
+
pointer-events: none;
|
77 |
+
z-index: 1000;
|
78 |
+
}
|
79 |
</style>
|
80 |
""", unsafe_allow_html=True)
|
81 |
|
82 |
+
# Confetti animation (for final reveal)
|
83 |
def show_confetti():
|
84 |
html("""
|
85 |
+
<canvas id="confetti-canvas" class="confetti"></canvas>
|
86 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
|
87 |
<script>
|
88 |
+
const canvas = document.getElementById('confetti-canvas');
|
89 |
+
const confetti = confetti.create(canvas, { resize: true });
|
90 |
+
|
91 |
+
confetti({
|
92 |
+
particleCount: 150,
|
93 |
+
spread: 70,
|
94 |
+
origin: { y: 0.6 }
|
95 |
+
});
|
96 |
+
|
97 |
+
setTimeout(() => {
|
98 |
+
canvas.remove();
|
99 |
+
}, 5000);
|
100 |
</script>
|
101 |
""")
|
102 |
|
103 |
+
# Game logic with fake data
|
104 |
def main():
|
105 |
inject_custom_css()
|
106 |
|
|
|
123 |
]
|
124 |
st.session_state.current_q = 0
|
125 |
st.session_state.answers = []
|
126 |
+
st.session_state.target = "smartphone" # Fake target for testing
|
127 |
|
128 |
# Start screen
|
129 |
if st.session_state.game_state == "start":
|
130 |
+
st.image("https://via.placeholder.com/600x300?text=Think+of+Something", use_column_width=True)
|
|
|
|
|
|
|
131 |
|
132 |
with st.form("start_form"):
|
133 |
category = st.radio("What are you thinking of?",
|
|
|
145 |
st.session_state.user_input = user_input
|
146 |
st.rerun()
|
147 |
|
148 |
+
# Gameplay screen
|
149 |
elif st.session_state.game_state == "gameplay":
|
150 |
col1, col2 = st.columns([1, 3])
|
151 |
with col1:
|
152 |
+
st.image("https://via.placeholder.com/200?text=Question", width=150)
|
|
|
|
|
|
|
153 |
with col2:
|
154 |
+
st.markdown(f'<div class="question-box">Question {st.session_state.current_q + 1}/10:<br><br>'
|
155 |
+
f'<strong>{st.session_state.questions[st.session_state.current_q]}</strong></div>',
|
156 |
+
unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
157 |
|
158 |
+
answer = st.radio("Your answer:", ["Yes", "No"], horizontal=True, label_visibility="collapsed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
if st.button("Submit Answer", type="primary"):
|
161 |
st.session_state.answers.append(answer == "Yes")
|
|
|
170 |
show_confetti()
|
171 |
st.markdown('<div class="final-reveal">🎉 I think it\'s a...</div>', unsafe_allow_html=True)
|
172 |
time.sleep(1)
|
173 |
+
st.markdown(f'<div class="final-reveal" style="font-size:3.5rem;color:#6C63FF;">{st.session_state.target.upper()}</div>',
|
174 |
+
unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
175 |
|
176 |
+
st.image("https://via.placeholder.com/400x200?text=Congratulations", use_column_width=True)
|
|
|
|
|
177 |
|
178 |
if st.button("Play Again", key="play_again"):
|
179 |
st.session_state.clear()
|