gouravgujariya commited on
Commit
2692382
โ€ข
1 Parent(s): 6763da3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -21
app.py CHANGED
@@ -4,30 +4,45 @@ from transformers import pipeline
4
  # Load the text generation model
5
  pipe = pipeline("text-generation", model="microsoft/Phi-3.5-mini-instruct", trust_remote_code=True)
6
 
7
- # Define a function to start the emoji game
 
 
 
 
 
 
 
 
 
8
  def emoji_game(user_guess=""):
9
- if user_guess == "": # If no guess yet, LLM asks the question first
10
- # LLM generates the first emoji sequence
11
- messages = [
12
- {"role": "user", "content": "Give me an emoji-based puzzle for a word or phrase guessing game."}
13
- ]
14
- response = pipe(messages)
15
- return response[0]['generated_text'] # Return the generated emoji puzzle
16
- else:
17
- # After the user makes a guess, the LLM evaluates the guess
18
- messages = [
19
- {"role": "user", "content": f"Guess the word or phrase represented by these emojis: {user_guess}."}
20
- ]
21
- response = pipe(messages)
22
- return response[0]['generated_text']
23
 
24
- # Create a Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
25
  interface = gr.Interface(
26
- fn=emoji_game, # Function to call when user submits input
27
- inputs="text", # Input widget (user types their guess)
28
- outputs="text", # Output widget (display model response)
29
- title="Guess the Word from Emojis",
30
- description="The LLM will first present an emoji puzzle, and you try to guess the word or phrase."
31
  )
32
 
33
  # Launch the interface
 
4
  # Load the text generation model
5
  pipe = pipeline("text-generation", model="microsoft/Phi-3.5-mini-instruct", trust_remote_code=True)
6
 
7
+ # Initialize variables for points
8
+ points = 0
9
+
10
+ # Function to reset points when the game starts or restarts
11
+ def reset_game():
12
+ global points
13
+ points = 0
14
+ return "Welcome to 'Guess the Word from Emojis'! You'll get emoji-based puzzles, and for each correct guess, you'll earn points. Wrong guesses will deduct points. Win by reaching 10 points, or lose if your score drops to -10. Let's get started! ๐Ÿ๐Ÿง™โšก = ???"
15
+
16
+ # Function to handle the game flow
17
  def emoji_game(user_guess=""):
18
+ global points
19
+
20
+ if user_guess == "": # Introduction step, LLM starts the conversation
21
+ return reset_game()
22
+
23
+ # LLM generates a response based on the user's guess
24
+ response = pipe([{"role": "user", "content": f"User guessed '{user_guess}'. Is it correct?"}])
25
+ response_text = response[0]['generated_text'].lower()
 
 
 
 
 
 
26
 
27
+ # Simple logic to simulate whether the LLM says the answer is right or wrong
28
+ if "correct" in response_text: # Correct answer
29
+ points += 1
30
+ if points >= 10:
31
+ return f"Correct! ๐ŸŽ‰ You've reached 10 points. You win the game!"
32
+ return f"Correct! Your current points: {points}. Keep going!"
33
+ else: # Wrong answer
34
+ points -= 1
35
+ if points <= -10:
36
+ return f"Incorrect! ๐Ÿ˜ข You've dropped to -10 points. Game over!"
37
+ return f"Incorrect! Your current points: {points}. Try again!"
38
+
39
+ # Gradio interface
40
  interface = gr.Interface(
41
+ fn=emoji_game, # The game logic function
42
+ inputs="text", # User input (guess)
43
+ outputs="text", # Text output (LLM response)
44
+ title="Guess the Word from Emojis Game",
45
+ description="Try to guess the word or phrase based on the emojis! ๐ŸŽฎ"
46
  )
47
 
48
  # Launch the interface