iisadia commited on
Commit
4db3cf5
·
verified ·
1 Parent(s): 98a3918

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -25
app.py CHANGED
@@ -137,6 +137,7 @@ def main():
137
  st.markdown('<div class="title">KASOTI</div>', unsafe_allow_html=True)
138
  st.markdown('<div class="subtitle">The Ultimate Guessing Game</div>', unsafe_allow_html=True)
139
 
 
140
  if 'game_state' not in st.session_state:
141
  st.session_state.game_state = "start"
142
  st.session_state.questions = []
@@ -144,8 +145,9 @@ def main():
144
  st.session_state.answers = []
145
  st.session_state.conversation_history = []
146
  st.session_state.category = None
147
- st.session_state.waiting_for_answer = False
148
-
 
149
  # Start screen
150
  if st.session_state.game_state == "start":
151
  st.markdown("""
@@ -172,21 +174,24 @@ def main():
172
  st.error("Please enter either 'person', 'place', or 'object'!")
173
  else:
174
  st.session_state.category = category_input
175
- # Generate first question
176
- first_question = ask_llama([{
177
- "role": "user",
178
- "content": "Ask your first yes/no question."
179
- }], category_input)
180
- st.session_state.questions = [first_question]
181
- st.session_state.conversation_history = [
182
- {"role": "assistant", "content": first_question}
183
- ]
184
  st.session_state.game_state = "gameplay"
185
- st.session_state.waiting_for_answer = True
186
  st.rerun()
187
 
188
- # Gameplay screen
189
  elif st.session_state.game_state == "gameplay":
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  # Show current question
191
  current_question = st.session_state.questions[st.session_state.current_q]
192
  st.markdown(f'<div class="question-box">Question {st.session_state.current_q + 1}/20:<br><br>'
@@ -206,24 +211,28 @@ def main():
206
  st.session_state.conversation_history.append(
207
  {"role": "user", "content": answer_input}
208
  )
 
209
 
210
  # Check if we've reached max questions
211
  if st.session_state.current_q >= 19:
212
  st.session_state.game_state = "result"
213
- else:
214
- # Generate next question based on all previous Q&A
215
- next_question = ask_llama(
216
- st.session_state.conversation_history,
217
- st.session_state.category
218
- )
219
- st.session_state.questions.append(next_question)
220
- st.session_state.conversation_history.append(
221
- {"role": "assistant", "content": next_question}
222
- )
223
- st.session_state.current_q += 1
224
-
225
  st.rerun()
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  # Early guess button
228
  if st.button("I think I can guess now!"):
229
  st.session_state.game_state = "result"
 
137
  st.markdown('<div class="title">KASOTI</div>', unsafe_allow_html=True)
138
  st.markdown('<div class="subtitle">The Ultimate Guessing Game</div>', unsafe_allow_html=True)
139
 
140
+ # Initialize session state
141
  if 'game_state' not in st.session_state:
142
  st.session_state.game_state = "start"
143
  st.session_state.questions = []
 
145
  st.session_state.answers = []
146
  st.session_state.conversation_history = []
147
  st.session_state.category = None
148
+ st.session_state.waiting_for_answer = True
149
+ st.session_state.question_generated = False
150
+
151
  # Start screen
152
  if st.session_state.game_state == "start":
153
  st.markdown("""
 
174
  st.error("Please enter either 'person', 'place', or 'object'!")
175
  else:
176
  st.session_state.category = category_input
 
 
 
 
 
 
 
 
 
177
  st.session_state.game_state = "gameplay"
 
178
  st.rerun()
179
 
180
+ # Gameplay screen - generate first question if needed
181
  elif st.session_state.game_state == "gameplay":
182
+ if not st.session_state.questions:
183
+ # Generate first question
184
+ first_question = ask_llama([{
185
+ "role": "user",
186
+ "content": "Ask your first yes/no question."
187
+ }], st.session_state.category)
188
+ st.session_state.questions = [first_question]
189
+ st.session_state.conversation_history = [
190
+ {"role": "assistant", "content": first_question}
191
+ ]
192
+ st.session_state.waiting_for_answer = True
193
+ st.rerun()
194
+
195
  # Show current question
196
  current_question = st.session_state.questions[st.session_state.current_q]
197
  st.markdown(f'<div class="question-box">Question {st.session_state.current_q + 1}/20:<br><br>'
 
211
  st.session_state.conversation_history.append(
212
  {"role": "user", "content": answer_input}
213
  )
214
+ st.session_state.waiting_for_answer = False
215
 
216
  # Check if we've reached max questions
217
  if st.session_state.current_q >= 19:
218
  st.session_state.game_state = "result"
 
 
 
 
 
 
 
 
 
 
 
 
219
  st.rerun()
220
 
221
+ # Generate next question if answer was submitted
222
+ if not st.session_state.waiting_for_answer and st.session_state.current_q < 19:
223
+ # Generate next question based on all previous Q&A
224
+ next_question = ask_llama(
225
+ st.session_state.conversation_history,
226
+ st.session_state.category
227
+ )
228
+ st.session_state.questions.append(next_question)
229
+ st.session_state.conversation_history.append(
230
+ {"role": "assistant", "content": next_question}
231
+ )
232
+ st.session_state.current_q += 1
233
+ st.session_state.waiting_for_answer = True
234
+ st.rerun()
235
+
236
  # Early guess button
237
  if st.button("I think I can guess now!"):
238
  st.session_state.game_state = "result"