Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
model_name = "openai-community/gpt2" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
def generate_text(prompt): | |
input_ids = tokenizer.encode(prompt, return_tensors='pt') | |
output = model.generate(input_ids, max_length=100) | |
return tokenizer.decode(output[0], skip_special_tokens=True) | |
def play_game(user_input): | |
# Example of integrating a simple game mechanic | |
prompt = f"You are in a dark forest. {user_input}" | |
response = generate_text(prompt) | |
return response | |
interface = gr.Interface( | |
fn=play_game, | |
inputs="text", | |
outputs="text", | |
title="Text-based RPG Adventure", | |
description="Enter actions or dialogue to interact with the game world." | |
) | |
interface.launch() |