iisadia commited on
Commit
06a931f
·
verified ·
1 Parent(s): 88c4e17

Update app.py

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