|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
import torch |
|
|
|
|
|
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") |
|
|
|
|
|
def summarize_text(input_text, min_length, max_length): |
|
|
|
|
|
summary = summarizer(input_text, min_length=min_length, max_length=max_length, do_sample=False) |
|
|
return summary[0]['summary_text'] |
|
|
|
|
|
|
|
|
interface = gr.Interface( |
|
|
fn=summarize_text, |
|
|
inputs=[ |
|
|
gr.Textbox(label="Enter Text", placeholder="Type or paste your long text here...", lines=10), |
|
|
gr.Slider(label="Minimum Length", minimum=10, maximum=50, step=1, value=10), |
|
|
gr.Slider(label="Maximum Length", minimum=50, maximum=150, step=1, value=100), |
|
|
], |
|
|
outputs=gr.Textbox(label="Summary"), |
|
|
title="Text Summarization App", |
|
|
description="Enter a long piece of text, set the summary length, and click the button to get a summarized version." |
|
|
) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
interface.launch() |