dlaima/summarisation
0
1import gradio as gr2from transformers import pipeline3 4# Load the summarization pipeline5pipe = pipeline("summarization", model="facebook/bart-large-cnn")6 7# Define the summarization function8def summarize_text(text, max_length=130, min_length=30, length_penalty=2.0):9 response = pipe(10 text,11 max_length=max_length,12 min_length=min_length,13 length_penalty=length_penalty,14 truncation=True15 )16 return response[0]['summary_text']17 18# Create the Gradio app interface19with gr.Blocks() as app:20 gr.Markdown("## Text Summarization App")21 gr.Markdown(22 "Enter a long text below, and the model will generate a concise summary. "23 "This app uses the `facebook/bart-large-cnn` model."24 )25 26 with gr.Row():27 input_text = gr.Textbox(28 label="Input Text",29 placeholder="Paste your text here...",30 lines=1031 )32 output_summary = gr.Textbox(label="Summary", lines=5)33 34 max_length = gr.Slider(35 label="Max Length", 36 minimum=50, 37 maximum=200, 38 step=10, 39 value=13040 )41 min_length = gr.Slider(42 label="Min Length", 43 minimum=10, 44 maximum=100, 45 step=10, 46 value=3047 )48 length_penalty = gr.Slider(49 label="Length Penalty", 50 minimum=0.5, 51 maximum=3.0, 52 step=0.1, 53 value=2.054 )55 56 submit_button = gr.Button("Summarize")57 58 submit_button.click(59 fn=summarize_text,60 inputs=[input_text, max_length, min_length, length_penalty],61 outputs=output_summary62 )63 64# Launch the app65if __name__ == "__main__":66 app.launch()67 