gouravgujariya commited on
Commit
6763da3
β€’
1 Parent(s): a18d07d

Update app.py

Browse files

updated version

Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -4,19 +4,22 @@ 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 for emoji guessing game
8
- def emoji_game(user_guess):
9
- # Messages to send to the model
10
- messages = [
11
- {"role": "user", "content": f"Guess the word or phrase represented by these emojis: πŸŽπŸ‘©β€πŸŒΎπŸšͺπŸͺž."},
12
- {"role": "user", "content": user_guess},
13
- ]
14
-
15
- # Generate response from the model
16
- response = pipe(messages)
17
-
18
- # Process the response (for simplicity, let's just return the generated text)
19
- return response[0]['generated_text']
 
 
 
20
 
21
  # Create a Gradio interface
22
  interface = gr.Interface(
@@ -24,7 +27,7 @@ interface = gr.Interface(
24
  inputs="text", # Input widget (user types their guess)
25
  outputs="text", # Output widget (display model response)
26
  title="Guess the Word from Emojis",
27
- description="Try to guess the word or phrase represented by the emojis. Example: πŸπŸ§™βš‘ = Harry Potter."
28
  )
29
 
30
  # 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
+ # 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(
 
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