Upload 2 files
Browse files- app.py +31 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
7 |
+
|
8 |
+
def summarize_text(text):
|
9 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
|
10 |
+
summary_ids = model.generate(
|
11 |
+
inputs["input_ids"],
|
12 |
+
attention_mask=inputs["attention_mask"],
|
13 |
+
max_length=100,
|
14 |
+
min_length=20,
|
15 |
+
length_penalty=2.0,
|
16 |
+
num_beams=4,
|
17 |
+
early_stopping=True,
|
18 |
+
no_repeat_ngram_size=3
|
19 |
+
)
|
20 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
21 |
+
return summary
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=summarize_text,
|
25 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
26 |
+
outputs=gr.Textbox(label="Summary"),
|
27 |
+
title="DistilBART Summarizer",
|
28 |
+
description="Summarize any input text using DistilBART fine-tuned model."
|
29 |
+
)
|
30 |
+
|
31 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
gradio
|