| import torch |
| import transformers |
| import gradio as gr |
| from transformers import pipeline |
|
|
| summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn") |
|
|
| text = """Paris is the capital and most populous city of France, with |
| an estimated population of 2,175,601 residents as of 2018, |
| in an area of more than 105 square kilometres (41 square |
| miles). The City of Paris is the centre and seat of |
| government of the region and province of Île-de-France, or |
| Paris Region, which has an estimated population of |
| 12,174,880, or about 18 percent of the population of France |
| as of 2017.""" |
|
|
| summary = summarizer(text, min_length=10, max_length=100) |
|
|
| summary |
|
|
| summary=summary[0]['summary_text'] |
| print(summary) |
|
|
|
|
| def summarization(text): |
| text = summary |
| return text |
|
|
| |
| iface = gr.Interface( |
| fn=summarization, |
| inputs=[ |
| gr.Textbox(placeholder="Enter text to summarize..."), |
| gr.Number(minimum=10, maximum=50, label="Minimum length"), |
| gr.Slider(minimum=50, maximum=150, step=1, label="Maximum length") |
| ], |
| outputs=gr.Textbox(label="Summary"), |
| title="Bart Summarization Model", |
| description="Enter a text or a paragraph to summarize its content: ", |
| ) |
|
|
| |
| if __name__ == "__main__": |
| iface.launch() |
|
|