jlincar commited on
Commit
ff3fd86
ยท
1 Parent(s): faeebed
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -26,6 +26,7 @@ class GameState:
26
  self.current_image = None
27
  self.correct_country = None
28
  self.ai_prediction = None
 
29
  self.options = []
30
  self.used_indices = []
31
 
@@ -82,25 +83,21 @@ def new_round():
82
  game.correct_country = sample["label"]
83
  game.current_image = image
84
 
85
- # Get AI prediction
86
  ai_pred, top3 = get_ai_prediction(image)
87
  game.ai_prediction = ai_pred
 
88
 
89
  # Generate options
90
  game.options = generate_options(game.correct_country, ai_pred)
91
 
92
- # AI confidence message
93
- ai_confidence = f"The AI predicts: **{ai_pred}**\n\n"
94
- ai_confidence += "Top 3 predictions:\n"
95
- for country, prob in top3:
96
- ai_confidence += f"- {country}: {prob*100:.1f}%\n"
97
-
98
  return (
99
  image,
100
- "๐ŸŒ **Where do you think this image is from?**\n\n" + ai_confidence,
101
  gr.update(choices=game.options, value=None, visible=True),
102
  gr.update(visible=True),
103
- f"๐ŸŽฎ Player: {game.player_score} | ๐Ÿค– AI: {game.ai_score} | ๐ŸŽฏ Rounds: {game.rounds}"
 
104
  )
105
 
106
  def check_answer(player_choice):
@@ -124,6 +121,7 @@ def check_answer(player_choice):
124
  result = f"## ๐ŸŽฏ Round {game.rounds} Result\n\n"
125
  result += f"**Correct country:** {game.correct_country}\n\n"
126
 
 
127
  if player_correct and ai_correct:
128
  result += "๐ŸŽ‰ **It's a tie!** Both you and the AI got it right!\n"
129
  elif player_correct:
@@ -136,11 +134,17 @@ def check_answer(player_choice):
136
  result += f"\n**Your answer:** {player_choice} {'โœ…' if player_correct else 'โŒ'}\n"
137
  result += f"**AI prediction:** {game.ai_prediction} {'โœ…' if ai_correct else 'โŒ'}\n"
138
 
 
 
 
 
 
139
  # Calculate win rate
140
  if game.rounds > 0:
141
  player_rate = (game.player_score / game.rounds) * 100
142
  ai_rate = (game.ai_score / game.rounds) * 100
143
- result += f"\n**Your accuracy:** {player_rate:.1f}% ({game.player_score}/{game.rounds})\n"
 
144
  result += f"**AI accuracy:** {ai_rate:.1f}% ({game.ai_score}/{game.rounds})\n"
145
 
146
  return result, gr.update(visible=True)
@@ -200,7 +204,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="GeoGuessr: Player vs AI") as demo:
200
  start_btn.click(
201
  fn=new_round,
202
  inputs=[],
203
- outputs=[image_display, question, options, submit_btn, scoreboard]
204
  )
205
 
206
  submit_btn.click(
@@ -223,4 +227,4 @@ with gr.Blocks(theme=gr.themes.Soft(), title="GeoGuessr: Player vs AI") as demo:
223
  """)
224
 
225
  if __name__ == "__main__":
226
- demo.launch()
 
26
  self.current_image = None
27
  self.correct_country = None
28
  self.ai_prediction = None
29
+ self.ai_top3 = None
30
  self.options = []
31
  self.used_indices = []
32
 
 
83
  game.correct_country = sample["label"]
84
  game.current_image = image
85
 
86
+ # Get AI prediction (but don't show it yet!)
87
  ai_pred, top3 = get_ai_prediction(image)
88
  game.ai_prediction = ai_pred
89
+ game.ai_top3 = top3
90
 
91
  # Generate options
92
  game.options = generate_options(game.correct_country, ai_pred)
93
 
 
 
 
 
 
 
94
  return (
95
  image,
96
+ "๐ŸŒ **Where do you think this image is from?**\n\nMake your choice before seeing the AI's prediction!",
97
  gr.update(choices=game.options, value=None, visible=True),
98
  gr.update(visible=True),
99
+ f"๐ŸŽฎ Player: {game.player_score} | ๐Ÿค– AI: {game.ai_score} | ๐ŸŽฏ Rounds: {game.rounds}",
100
+ "" # Clear previous result
101
  )
102
 
103
  def check_answer(player_choice):
 
121
  result = f"## ๐ŸŽฏ Round {game.rounds} Result\n\n"
122
  result += f"**Correct country:** {game.correct_country}\n\n"
123
 
124
+ # Show comparison
125
  if player_correct and ai_correct:
126
  result += "๐ŸŽ‰ **It's a tie!** Both you and the AI got it right!\n"
127
  elif player_correct:
 
134
  result += f"\n**Your answer:** {player_choice} {'โœ…' if player_correct else 'โŒ'}\n"
135
  result += f"**AI prediction:** {game.ai_prediction} {'โœ…' if ai_correct else 'โŒ'}\n"
136
 
137
+ # Show AI's top 3 predictions
138
+ result += f"\n**AI's top 3 predictions:**\n"
139
+ for country, prob in game.ai_top3:
140
+ result += f"- {country}: {prob*100:.1f}%\n"
141
+
142
  # Calculate win rate
143
  if game.rounds > 0:
144
  player_rate = (game.player_score / game.rounds) * 100
145
  ai_rate = (game.ai_score / game.rounds) * 100
146
+ result += f"\n---\n"
147
+ result += f"**Your accuracy:** {player_rate:.1f}% ({game.player_score}/{game.rounds})\n"
148
  result += f"**AI accuracy:** {ai_rate:.1f}% ({game.ai_score}/{game.rounds})\n"
149
 
150
  return result, gr.update(visible=True)
 
204
  start_btn.click(
205
  fn=new_round,
206
  inputs=[],
207
+ outputs=[image_display, question, options, submit_btn, scoreboard, result]
208
  )
209
 
210
  submit_btn.click(
 
227
  """)
228
 
229
  if __name__ == "__main__":
230
+ demo.launch()