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) # Define a function to start the emoji game def emoji_game(user_guess=""): if user_guess == "": # If no guess yet, LLM asks the question first # LLM generates the first emoji sequence messages = [ {"role": "user", "content": "Give me an emoji-based puzzle for a word or phrase guessing game."} ] response = pipe(messages) return response[0]['generated_text'] # Return the generated emoji puzzle else: # After the user makes a guess, the LLM evaluates the guess messages = [ {"role": "user", "content": f"Guess the word or phrase represented by these emojis: {user_guess}."} ] response = pipe(messages) return response[0]['generated_text'] # Create a Gradio interface interface = gr.Interface( fn=emoji_game, # Function to call when user submits input inputs="text", # Input widget (user types their guess) outputs="text", # Output widget (display model response) title="Guess the Word from Emojis", description="The LLM will first present an emoji puzzle, and you try to guess the word or phrase." ) # Launch the interface interface.launch()