Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline, Seq2SeqTrainer, Seq2SeqTrainingArguments
|
3 |
+
|
4 |
+
model_path = 'T5_samsum'
|
5 |
+
|
6 |
+
# Load the model
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
8 |
+
|
9 |
+
# Load the tokenizer
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
11 |
+
|
12 |
+
# Create the summarization pipeline
|
13 |
+
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
|
14 |
+
|
15 |
+
# Define the summarization function
|
16 |
+
def summarize_dialogue(dialogue):
|
17 |
+
summary = summarizer(dialogue, max_length=150, min_length=50, do_sample=False)
|
18 |
+
return summary[0]['summary_text']
|
19 |
+
|
20 |
+
# Create the Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=summarize_dialogue,
|
23 |
+
inputs=gr.Textbox(lines=10, placeholder="Enter the dialogue here..."),
|
24 |
+
outputs="text",
|
25 |
+
title="Dialogue Summarizer",
|
26 |
+
description="Enter a dialogue and this app will generate a summary using a pre-trained model."
|
27 |
+
)
|
28 |
+
|
29 |
+
# Launch the app
|
30 |
+
iface.launch()
|