Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
# Load GPT-2 model | |
generator = pipeline("text-generation", model="gpt2-medium") | |
def generate_insult(name, location, job, hobbies, tone): | |
# Create a structured prompt for GPT-2 | |
prompt = f"You are a sarcastic AI. Here is a person named {name} from {location}. They work as a {job} and enjoy {hobbies}. Now, insult them in a {tone} way. Keep it short and direct." | |
# Generate response from GPT-2 | |
response = generator(prompt, max_length=50, num_return_sequences=1) | |
return response[0]['generated_text'].replace(prompt, "").strip() | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=generate_insult, | |
inputs=[ | |
gr.Textbox(label="Name"), | |
gr.Textbox(label="Location"), | |
gr.Textbox(label="Job"), | |
gr.Textbox(label="Hobbies"), | |
gr.Dropdown(choices=["mild", "savage", "neutral", "affirmation"], label="Tone"), | |
], | |
outputs="text", | |
) | |
# Launch the API | |
iface.launch() |