gouravgujariya commited on
Commit
286a0cd
โ€ข
1 Parent(s): 7952d76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -17,7 +17,7 @@ def reset_game():
17
 
18
  # Ask LLM for the first emoji puzzle
19
  emoji_prompt = "Give me an emoji-based puzzle for a word or phrase guessing game."
20
- response = pipe([{"role": "user", "content": emoji_prompt}])
21
  current_emoji = response[0]['generated_text']
22
 
23
  return introduction + f"Here's your first puzzle: {current_emoji}"
@@ -45,7 +45,7 @@ def emoji_game(user_input=""):
45
 
46
  # Check if the user made a guess; LLM evaluates the guess
47
  guess_prompt = f"User guessed '{user_input}'. Was the guess correct for this emoji puzzle: {current_emoji}?"
48
- response = pipe([{"role": "user", "content": guess_prompt}])
49
  response_text = response[0]['generated_text'].lower()
50
 
51
  # Process response: if it's correct, increase points; otherwise, decrease points
@@ -56,7 +56,7 @@ def emoji_game(user_input=""):
56
  else:
57
  # Get next emoji puzzle for the user
58
  next_emoji_prompt = "Give me another emoji-based puzzle."
59
- response = pipe([{"role": "user", "content": next_emoji_prompt}])
60
  current_emoji = response[0]['generated_text']
61
  return f"โœ… Correct! Your current points: {points}. Here's your next puzzle: {current_emoji}"
62
  else: # Incorrect guess
@@ -66,14 +66,19 @@ def emoji_game(user_input=""):
66
  else:
67
  return f"โŒ Incorrect! Your current points: {points}. Try again: {current_emoji}"
68
 
69
- # Create a Gradio interface for the game
70
- interface = gr.Interface(
71
- fn=emoji_game, # Game logic function
72
- inputs="text", # Text input for user guess
73
- outputs="text", # Text output for LLM responses
74
- title="Guess the Word from Emojis Game",
75
- description="Try to guess the word or phrase based on the emojis! ๐ŸŽฎ Reach 10 points to win or drop to -10 points to lose!"
76
- )
 
 
 
 
 
77
 
78
  # Launch the Gradio interface
79
  interface.launch()
 
17
 
18
  # Ask LLM for the first emoji puzzle
19
  emoji_prompt = "Give me an emoji-based puzzle for a word or phrase guessing game."
20
+ response = pipe([{"role": "user", "content": emoji_prompt}], max_new_tokens=30)
21
  current_emoji = response[0]['generated_text']
22
 
23
  return introduction + f"Here's your first puzzle: {current_emoji}"
 
45
 
46
  # Check if the user made a guess; LLM evaluates the guess
47
  guess_prompt = f"User guessed '{user_input}'. Was the guess correct for this emoji puzzle: {current_emoji}?"
48
+ response = pipe([{"role": "user", "content": guess_prompt}], max_new_tokens=30)
49
  response_text = response[0]['generated_text'].lower()
50
 
51
  # Process response: if it's correct, increase points; otherwise, decrease points
 
56
  else:
57
  # Get next emoji puzzle for the user
58
  next_emoji_prompt = "Give me another emoji-based puzzle."
59
+ response = pipe([{"role": "user", "content": next_emoji_prompt}], max_new_tokens=30)
60
  current_emoji = response[0]['generated_text']
61
  return f"โœ… Correct! Your current points: {points}. Here's your next puzzle: {current_emoji}"
62
  else: # Incorrect guess
 
66
  else:
67
  return f"โŒ Incorrect! Your current points: {points}. Try again: {current_emoji}"
68
 
69
+ # Create a Gradio interface for the game with horizontal layout and buttons
70
+ with gr.Blocks() as interface:
71
+ gr.Markdown("### Guess the Word from Emojis Game ๐ŸŽฎ")
72
+ output = gr.Textbox(label="Game Output", interactive=False)
73
+ input_box = gr.Textbox(label="Your Guess or Command")
74
+
75
+ with gr.Row():
76
+ start_button = gr.Button("Start Game")
77
+ next_button = gr.Button("Next Puzzle")
78
+
79
+ input_box.submit(emoji_game, inputs=input_box, outputs=output)
80
+ start_button.click(reset_game, outputs=output)
81
+ next_button.click(lambda: emoji_game(), outputs=output)
82
 
83
  # Launch the Gradio interface
84
  interface.launch()