summarisation / app.py
dlaima's picture
Create app.py
ea424b3 verified
import gradio as gr
from transformers import pipeline
# Load the summarization pipeline
pipe = pipeline("summarization", model="facebook/bart-large-cnn")
# Define the summarization function
def summarize_text(text, max_length=130, min_length=30, length_penalty=2.0):
response = pipe(
text,
max_length=max_length,
min_length=min_length,
length_penalty=length_penalty,
truncation=True
)
return response[0]['summary_text']
# Create the Gradio app interface
with gr.Blocks() as app:
gr.Markdown("## Text Summarization App")
gr.Markdown(
"Enter a long text below, and the model will generate a concise summary. "
"This app uses the `facebook/bart-large-cnn` model."
)
with gr.Row():
input_text = gr.Textbox(
label="Input Text",
placeholder="Paste your text here...",
lines=10
)
output_summary = gr.Textbox(label="Summary", lines=5)
max_length = gr.Slider(
label="Max Length",
minimum=50,
maximum=200,
step=10,
value=130
)
min_length = gr.Slider(
label="Min Length",
minimum=10,
maximum=100,
step=10,
value=30
)
length_penalty = gr.Slider(
label="Length Penalty",
minimum=0.5,
maximum=3.0,
step=0.1,
value=2.0
)
submit_button = gr.Button("Summarize")
submit_button.click(
fn=summarize_text,
inputs=[input_text, max_length, min_length, length_penalty],
outputs=output_summary
)
# Launch the app
if __name__ == "__main__":
app.launch()