Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# Load dataset (optional if you want random roast sampling)
|
| 7 |
+
dataset = load_dataset("gus-gustavo/reddit_roastme")
|
| 8 |
+
|
| 9 |
+
# Use DialoGPT from Hugging Face
|
| 10 |
+
generator = pipeline("text-generation", model="microsoft/DialoGPT-large")
|
| 11 |
+
|
| 12 |
+
def roast_me(prompt):
|
| 13 |
+
# Generate roast using DialoGPT
|
| 14 |
+
response = generator(prompt, max_length=100, do_sample=True)[0]["generated_text"]
|
| 15 |
+
return response
|
| 16 |
+
|
| 17 |
+
# Option B: Just sample from dataset
|
| 18 |
+
def random_roast(_):
|
| 19 |
+
return random.choice(dataset["train"])["body"]
|
| 20 |
+
|
| 21 |
+
# Gradio interface
|
| 22 |
+
interface = gr.Interface(
|
| 23 |
+
fn=roast_me, # swap to random_roast if you want dataset-only
|
| 24 |
+
inputs="text",
|
| 25 |
+
outputs="text",
|
| 26 |
+
title="RoastBot",
|
| 27 |
+
description="A chatbot that roasts you using Microsoft DialoGPT or random roasts from Reddit's RoastMe dataset."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
interface.launch()
|