gouravgujariya commited on
Commit
48857de
โ€ข
1 Parent(s): e92b92d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
3
 
4
  # Load the text generation model
5
  pipe = pipeline("text-generation", model="microsoft/Phi-3.5-mini-instruct", trust_remote_code=True)
@@ -8,6 +10,14 @@ pipe = pipeline("text-generation", model="microsoft/Phi-3.5-mini-instruct", trus
8
  points = 0
9
  current_emoji = ""
10
 
 
 
 
 
 
 
 
 
11
  # Function to reset the game and initialize introduction
12
  def reset_game():
13
  global points, current_emoji
@@ -15,12 +25,8 @@ def reset_game():
15
  # LLM introduces the game and asks the first emoji puzzle
16
  introduction = "Welcome to 'Guess the Word from Emojis'! ๐ŸŽฎ Here's how it works:\n\n- You'll get an emoji-based puzzle.\n- For each correct guess, you'll earn 1 point.\n- Wrong guesses will deduct 1 point.\n- Win by reaching 10 points, or lose if your score drops to -10 points.\n\nLet's begin!\n"
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
-
22
- # Ensure to get the generated text correctly
23
- current_emoji = response[0]['generated_text'] if response and isinstance(response, list) and len(response) > 0 else "โ“"
24
 
25
  # Return introduction and the emoji puzzle
26
  return introduction + f"Here's your first puzzle: {current_emoji}"
@@ -60,11 +66,7 @@ def emoji_game(user_input=""):
60
  return f"๐ŸŽ‰ Correct! You've reached 10 points! You win the game! ๐Ÿ†"
61
  else:
62
  # Get next emoji puzzle for the user
63
- next_emoji_prompt = "Give me another emoji-based puzzle."
64
- response = pipe([{"role": "user", "content": next_emoji_prompt}], max_new_tokens=30)
65
-
66
- # Ensure to get the generated text correctly
67
- current_emoji = response[0]['generated_text'] if response and isinstance(response, list) and len(response) > 0 else "โ“"
68
  return f"โœ… Correct! Your current points: {points}. Here's your next puzzle: {current_emoji}"
69
  else: # Incorrect guess
70
  points -= 1
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import emoji
4
+ import random
5
 
6
  # Load the text generation model
7
  pipe = pipeline("text-generation", model="microsoft/Phi-3.5-mini-instruct", trust_remote_code=True)
 
10
  points = 0
11
  current_emoji = ""
12
 
13
+ # Predefined emoji puzzles
14
+ emoji_puzzles = [
15
+ emoji.emojize(":snake:") + emoji.emojize(":wizard:") + emoji.emojize(":lightning:"),
16
+ emoji.emojize(":apple:") + emoji.emojize(":woman_farmer:") + emoji.emojize(":door:") + emoji.emojize(":mirror:"),
17
+ emoji.emojize(":dog:") + emoji.emojize(":house:"),
18
+ emoji.emojize(":pizza:") + emoji.emojize(":slice:"),
19
+ ]
20
+
21
  # Function to reset the game and initialize introduction
22
  def reset_game():
23
  global points, current_emoji
 
25
  # LLM introduces the game and asks the first emoji puzzle
26
  introduction = "Welcome to 'Guess the Word from Emojis'! ๐ŸŽฎ Here's how it works:\n\n- You'll get an emoji-based puzzle.\n- For each correct guess, you'll earn 1 point.\n- Wrong guesses will deduct 1 point.\n- Win by reaching 10 points, or lose if your score drops to -10 points.\n\nLet's begin!\n"
27
 
28
+ # Randomly select an emoji puzzle
29
+ current_emoji = random.choice(emoji_puzzles)
 
 
 
 
30
 
31
  # Return introduction and the emoji puzzle
32
  return introduction + f"Here's your first puzzle: {current_emoji}"
 
66
  return f"๐ŸŽ‰ Correct! You've reached 10 points! You win the game! ๐Ÿ†"
67
  else:
68
  # Get next emoji puzzle for the user
69
+ current_emoji = random.choice(emoji_puzzles)
 
 
 
 
70
  return f"โœ… Correct! Your current points: {points}. Here's your next puzzle: {current_emoji}"
71
  else: # Incorrect guess
72
  points -= 1