File size: 984 Bytes
87573d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
efb1a3f
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
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()