File size: 824 Bytes
5833b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa08f67
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
import gradio as gr
from transformers import pipeline

# Load the summarization model
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

def generate_summary(text):
    input_length = len(text.split())
    max_length = min(200, input_length + 20)
    min_length = min(50, max_length // 2)
    
    summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=True, temperature=0.7)
    return summary[0]['summary_text']

# Define the Gradio interface
iface = gr.Interface(
    fn=generate_summary,
    inputs=gr.Textbox(lines=5, placeholder="Enter text here..."),
    outputs=gr.Textbox(label="Summary"),
    title="Text Summarization with Transformers",
    description="Enter a text passage, and the model will generate a summarized version."
)

# Launch the GUI
iface.launch()