Spaces:
Runtime error
Runtime error
gouravgujariya
commited on
Commit
โข
2692382
1
Parent(s):
6763da3
Update app.py
Browse files
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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def emoji_game(user_guess=""):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
interface = gr.Interface(
|
26 |
-
fn=emoji_game, #
|
27 |
-
inputs="text", #
|
28 |
-
outputs="text", #
|
29 |
-
title="Guess the Word from Emojis",
|
30 |
-
description="
|
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
|