iisadia commited on
Commit
12df84a
·
verified ·
1 Parent(s): 72b5667

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -20
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import streamlit as st
2
  import time
3
- import random
4
  from streamlit.components.v1 import html
5
 
6
  # Custom CSS for professional look
@@ -127,30 +126,42 @@ def main():
127
 
128
  # Start screen
129
  if st.session_state.game_state == "start":
130
-
131
-
 
 
 
 
 
 
 
 
 
 
 
 
132
  with st.form("start_form"):
133
- category = st.radio("What are you thinking of?",
134
- ["A famous person", "An object", "A place"],
135
- index=1)
136
- user_input = st.text_input("Type it here (we won't peek!):").strip().lower()
137
-
138
  if st.form_submit_button("Start Game"):
139
- if not user_input:
140
- st.error("Please type something!")
 
 
141
  elif len(user_input) < 3:
142
  st.error("Too short! Type properly.")
143
  else:
144
- st.session_state.game_state = "gameplay"
145
  st.session_state.user_input = user_input
 
146
  st.rerun()
147
-
148
  # Gameplay screen
149
  elif st.session_state.game_state == "gameplay":
150
-
151
  st.markdown(f'<div class="question-box">Question {st.session_state.current_q + 1}/10:<br><br>'
152
- f'<strong>{st.session_state.questions[st.session_state.current_q]}</strong></div>',
153
- unsafe_allow_html=True)
154
 
155
  answer = st.radio("Your answer:", ["Yes", "No"], horizontal=True, label_visibility="collapsed")
156
 
@@ -161,19 +172,18 @@ def main():
161
  if st.session_state.current_q >= len(st.session_state.questions):
162
  st.session_state.game_state = "result"
163
  st.rerun()
164
-
165
  # Result screen
166
  elif st.session_state.game_state == "result":
167
  show_confetti()
168
  st.markdown('<div class="final-reveal">🎉 I think it\'s a...</div>', unsafe_allow_html=True)
169
  time.sleep(1)
170
- st.markdown(f'<div class="final-reveal" style="font-size:3.5rem;color:#6C63FF;">{st.session_state.target.upper()}</div>',
171
- unsafe_allow_html=True)
172
-
173
 
174
  if st.button("Play Again", key="play_again"):
175
  st.session_state.clear()
176
  st.rerun()
177
 
178
  if __name__ == "__main__":
179
- main()
 
1
  import streamlit as st
2
  import time
 
3
  from streamlit.components.v1 import html
4
 
5
  # Custom CSS for professional look
 
126
 
127
  # Start screen
128
  if st.session_state.game_state == "start":
129
+ st.markdown("""
130
+ <div class="question-box">
131
+ <h3>Welcome to <span style='color:#6C63FF;'>KASOTI 🎯</span></h3>
132
+ <p>This is a fun guessing game! You’ll think of something, and I’ll ask 10 Yes/No questions to guess what it is.</p>
133
+ <p>You can choose from three categories:</p>
134
+ <ul>
135
+ <li><strong>person</strong> – like a celebrity, fictional character, etc.</li>
136
+ <li><strong>place</strong> – like a city, country, or location</li>
137
+ <li><strong>object</strong> – like something you can touch or use</li>
138
+ </ul>
139
+ <p><strong>Type one of these categories below</strong> to begin: <code>person</code>, <code>place</code>, or <code>object</code>.</p>
140
+ </div>
141
+ """, unsafe_allow_html=True)
142
+
143
  with st.form("start_form"):
144
+ category_input = st.text_input("Enter category (person / place / object):").strip().lower()
145
+ user_input = st.text_input("Now think of something in that category (we won't peek!):").strip().lower()
146
+
 
 
147
  if st.form_submit_button("Start Game"):
148
+ if not category_input or not user_input:
149
+ st.error("Please fill out both fields!")
150
+ elif category_input not in ["person", "place", "object"]:
151
+ st.error("Oops! Type either person, place or object to start the game!")
152
  elif len(user_input) < 3:
153
  st.error("Too short! Type properly.")
154
  else:
155
+ st.session_state.category = category_input
156
  st.session_state.user_input = user_input
157
+ st.session_state.game_state = "gameplay"
158
  st.rerun()
159
+
160
  # Gameplay screen
161
  elif st.session_state.game_state == "gameplay":
 
162
  st.markdown(f'<div class="question-box">Question {st.session_state.current_q + 1}/10:<br><br>'
163
+ f'<strong>{st.session_state.questions[st.session_state.current_q]}</strong></div>',
164
+ unsafe_allow_html=True)
165
 
166
  answer = st.radio("Your answer:", ["Yes", "No"], horizontal=True, label_visibility="collapsed")
167
 
 
172
  if st.session_state.current_q >= len(st.session_state.questions):
173
  st.session_state.game_state = "result"
174
  st.rerun()
175
+
176
  # Result screen
177
  elif st.session_state.game_state == "result":
178
  show_confetti()
179
  st.markdown('<div class="final-reveal">🎉 I think it\'s a...</div>', unsafe_allow_html=True)
180
  time.sleep(1)
181
+ st.markdown(f'<div class="final-reveal" style="font-size:3.5rem;color:#6C63FF;">{st.session_state.user_input.upper()}</div>',
182
+ unsafe_allow_html=True)
 
183
 
184
  if st.button("Play Again", key="play_again"):
185
  st.session_state.clear()
186
  st.rerun()
187
 
188
  if __name__ == "__main__":
189
+ main()