File size: 1,262 Bytes
ca47e9b
 
26628e2
fbddca2
697b008
ca47e9b
 
 
 
 
 
 
e5f9d0d
ca47e9b
 
fbddca2
 
11d5370
fbddca2
1ddbd5c
 
 
 
 
 
 
 
fbddca2
 
ca47e9b
 
 
 
fbddca2
 
1ddbd5c
fbddca2
848f38c
fbddca2
ca47e9b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


import gradio as gr
from transformers import pipeline

# Step 3: Define the summarization function for multiple models
summarizers = {
    "BART (facebook/bart-large-cnn)": pipeline("summarization", model="facebook/bart-large-cnn"),
    "T5 (t5-small)": pipeline("summarization", model="t5-small"),
    "Pegasus (google/pegasus-xsum)": pipeline("summarization", model="google/pegasus-xsum"),
    "DistilBART (sshleifer/distilbart-cnn-12-6)": pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
}

def summarize(text, model_name):
    summarizer = summarizers[model_name]
    summary = summarizer(text, max_length=150, min_length=40, do_sample=False)
    return summary[0]['summary_text']

# Step 4: Create the Gradio interface
description = """
Summarize text using various models from Hugging Face:
- BART (facebook/bart-large-cnn)
- T5 (t5-small)
- Pegasus (google/pegasus-xsum)
- DistilBART (sshleifer/distilbart-cnn-12-6)
"""

iface = gr.Interface(
    fn=summarize,
    inputs=[
        gr.Textbox(lines=10, label="Input Text"),
        gr.Dropdown(choices=list(summarizers.keys()), label="Choose Model")
    ],
    outputs="textbox",
    title="Text Summarizer",
    description=description
)

# Step 5: Launch the interface
iface.launch()