File size: 1,927 Bytes
1e7d879
 
 
 
 
 
2692382
 
 
 
 
 
 
 
 
 
6763da3
2692382
 
 
 
 
 
 
 
1e7d879
2692382
 
 
 
 
 
 
 
 
 
 
 
 
1e7d879
2692382
 
 
 
 
1e7d879
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
from transformers import pipeline

# Load the text generation model
pipe = pipeline("text-generation", model="microsoft/Phi-3.5-mini-instruct", trust_remote_code=True)

# Initialize variables for points
points = 0

# Function to reset points when the game starts or restarts
def reset_game():
    global points
    points = 0
    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! ๐Ÿ๐Ÿง™โšก = ???"

# Function to handle the game flow
def emoji_game(user_guess=""):
    global points

    if user_guess == "":  # Introduction step, LLM starts the conversation
        return reset_game()
    
    # LLM generates a response based on the user's guess
    response = pipe([{"role": "user", "content": f"User guessed '{user_guess}'. Is it correct?"}])
    response_text = response[0]['generated_text'].lower()

    # Simple logic to simulate whether the LLM says the answer is right or wrong
    if "correct" in response_text:  # Correct answer
        points += 1
        if points >= 10:
            return f"Correct! ๐ŸŽ‰ You've reached 10 points. You win the game!"
        return f"Correct! Your current points: {points}. Keep going!"
    else:  # Wrong answer
        points -= 1
        if points <= -10:
            return f"Incorrect! ๐Ÿ˜ข You've dropped to -10 points. Game over!"
        return f"Incorrect! Your current points: {points}. Try again!"
    
# Gradio interface
interface = gr.Interface(
    fn=emoji_game,  # The game logic function
    inputs="text",  # User input (guess)
    outputs="text",  # Text output (LLM response)
    title="Guess the Word from Emojis Game",
    description="Try to guess the word or phrase based on the emojis! ๐ŸŽฎ"
)

# Launch the interface
interface.launch()