Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load GPT-2 model
|
| 5 |
+
generator = pipeline("text-generation", model="gpt2-medium")
|
| 6 |
+
|
| 7 |
+
def generate_insult(name, location, job, hobbies, tone):
|
| 8 |
+
# Create a structured prompt for GPT-2
|
| 9 |
+
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."
|
| 10 |
+
|
| 11 |
+
# Generate response from GPT-2
|
| 12 |
+
response = generator(prompt, max_length=50, num_return_sequences=1)
|
| 13 |
+
return response[0]['generated_text'].replace(prompt, "").strip()
|
| 14 |
+
|
| 15 |
+
# Create the Gradio interface
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=generate_insult,
|
| 18 |
+
inputs=[
|
| 19 |
+
gr.Textbox(label="Name"),
|
| 20 |
+
gr.Textbox(label="Location"),
|
| 21 |
+
gr.Textbox(label="Job"),
|
| 22 |
+
gr.Textbox(label="Hobbies"),
|
| 23 |
+
gr.Dropdown(choices=["mild", "savage", "neutral", "affirmation"], label="Tone"),
|
| 24 |
+
],
|
| 25 |
+
outputs="text",
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Launch the API
|
| 29 |
+
iface.launch()py
|