iisadia commited on
Commit
d8d5ad4
·
verified ·
1 Parent(s): 231b0e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -28
app.py CHANGED
@@ -41,7 +41,7 @@ def inject_custom_css():
41
  padding: 2rem;
42
  margin: 1.5rem 0;
43
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
44
- color: black !important; /* Force black text */
45
  }
46
 
47
  .answer-btn {
@@ -122,8 +122,8 @@ def ask_llama(conversation_history, category, is_final_guess=False):
122
  1. Ask strategic, non-repeating yes/no questions that narrow down possibilities
123
  2. Consider all previous answers carefully before asking next question
124
  3. If you're very confident (80%+ sure), respond with "Final Guess: [your guess]"
125
- 4. For places: ask about continent, climate, famous landmarks, or population
126
- 5. For people: ask about profession, gender, alive/dead, nationality, or fame
127
  6. For objects: ask about size, color, usage, material, or where it's found
128
  7. Never repeat questions and always make progress toward guessing"""
129
 
@@ -279,35 +279,38 @@ def main():
279
  st.markdown(f"**You:** {msg['query']}")
280
  st.markdown(f"**Help Assistant:** {msg['response']}")
281
 
282
- # Guess confirmation screen
283
  elif st.session_state.game_state == "confirm_guess":
284
  st.markdown(f'<div class="question-box">🤖 My Final Guess:<br><br>'
285
  f'<strong>Is it {st.session_state.final_guess}?</strong></div>',
286
  unsafe_allow_html=True)
287
 
288
- col1, col2 = st.columns(2)
289
- with col1:
290
- if st.button("Yes! You're correct!", key="correct_guess", use_container_width=True):
291
- st.session_state.game_state = "result"
292
- st.rerun()
293
- with col2:
294
- if st.button("No, try again", key="wrong_guess", use_container_width=True):
295
- # Add negative response to history and continue
296
- st.session_state.conversation_history.append(
297
- {"role": "user", "content": "no"}
298
- )
299
- st.session_state.game_state = "gameplay"
300
- # Generate follow-up question
301
- next_response = ask_llama(
302
- st.session_state.conversation_history,
303
- st.session_state.category
304
- )
305
- st.session_state.questions.append(next_response)
306
- st.session_state.conversation_history.append(
307
- {"role": "assistant", "content": next_response}
308
- )
309
- st.session_state.current_q += 1
310
- st.rerun()
 
 
 
311
 
312
  # Result screen
313
  elif st.session_state.game_state == "result":
@@ -338,4 +341,4 @@ def main():
338
  st.rerun()
339
 
340
  if __name__ == "__main__":
341
- main()
 
41
  padding: 2rem;
42
  margin: 1.5rem 0;
43
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
44
+ color: black !important;
45
  }
46
 
47
  .answer-btn {
 
122
  1. Ask strategic, non-repeating yes/no questions that narrow down possibilities
123
  2. Consider all previous answers carefully before asking next question
124
  3. If you're very confident (80%+ sure), respond with "Final Guess: [your guess]"
125
+ 4. For places: ask about continent, climate, famous landmarks, country, city or population
126
+ 5. For people: ask about fictional or real, profession, gender, alive/dead, nationality, or fame
127
  6. For objects: ask about size, color, usage, material, or where it's found
128
  7. Never repeat questions and always make progress toward guessing"""
129
 
 
279
  st.markdown(f"**You:** {msg['query']}")
280
  st.markdown(f"**Help Assistant:** {msg['response']}")
281
 
282
+ # Guess confirmation screen using text input response
283
  elif st.session_state.game_state == "confirm_guess":
284
  st.markdown(f'<div class="question-box">🤖 My Final Guess:<br><br>'
285
  f'<strong>Is it {st.session_state.final_guess}?</strong></div>',
286
  unsafe_allow_html=True)
287
 
288
+ with st.form("confirm_form"):
289
+ confirm_input = st.text_input("Type your answer (yes/no/both):", key="confirm_input").strip().lower()
290
+ if st.form_submit_button("Submit"):
291
+ if confirm_input not in ["yes", "no", "both"]:
292
+ st.error("Please answer with 'yes', 'no', or 'both'!")
293
+ else:
294
+ if confirm_input == "yes":
295
+ st.session_state.game_state = "result"
296
+ st.rerun()
297
+ st.stop() # Immediately halt further execution
298
+ else:
299
+ # Add negative response to history and continue gameplay
300
+ st.session_state.conversation_history.append(
301
+ {"role": "user", "content": "no"}
302
+ )
303
+ st.session_state.game_state = "gameplay"
304
+ next_response = ask_llama(
305
+ st.session_state.conversation_history,
306
+ st.session_state.category
307
+ )
308
+ st.session_state.questions.append(next_response)
309
+ st.session_state.conversation_history.append(
310
+ {"role": "assistant", "content": next_response}
311
+ )
312
+ st.session_state.current_q += 1
313
+ st.rerun()
314
 
315
  # Result screen
316
  elif st.session_state.game_state == "result":
 
341
  st.rerun()
342
 
343
  if __name__ == "__main__":
344
+ main()