Spaces:
Runtime error
Runtime error
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() | |