Spaces:
Sleeping
Sleeping
Upload reddit_demo.py
Browse files- reddit_demo.py +23 -0
reddit_demo.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
3 |
+
|
4 |
+
if __name__ == "__main__":
|
5 |
+
# Load finetuned model and tokenizer
|
6 |
+
tokenizer = BartTokenizer.from_pretrained("NielsV/distilbart-cnn-6-6-reddit")
|
7 |
+
model = BartForConditionalGeneration.from_pretrained("NielsV/distilbart-cnn-6-6-reddit")
|
8 |
+
|
9 |
+
# Function to write a TLDR
|
10 |
+
def generate_tldr(input_txt):
|
11 |
+
inputs = tokenizer(input_txt, max_length=1024, return_tensors="pt")
|
12 |
+
summary_ids = model.generate(inputs["input_ids"], num_beams=2, min_length=0, max_length=60)
|
13 |
+
return tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
14 |
+
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=generate_tldr,
|
17 |
+
inputs=gr.Textbox(lines=5, placeholder="...", label="Post to summarize..."),
|
18 |
+
outputs=gr.Textbox(lines=2, label="Too long, didn't read:"),
|
19 |
+
title="Too long, didn't read",
|
20 |
+
description="A tldr-bot trained on reddit posts."
|
21 |
+
)
|
22 |
+
|
23 |
+
demo.launch()
|