Spaces:
Sleeping
Sleeping
| # Import libraries | |
| import gradio as gr | |
| import torch as torch | |
| from transformers import pipeline | |
| # Create a summarization pipeline | |
| # summarizer = pipeline("summarization") | |
| #text_summery = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") | |
| text_summery = pipeline("summarization", model="sshleifer/distilbart-cnn-6-6") | |
| #text_summery = pipeline("summarization", model="facebook/bart-large-cnn") | |
| #text_summery = pipeline("summarization", model="google/pegasus-xsum") | |
| # Define a function that takes a text and returns a summary | |
| def summarize(text): | |
| summary = text_summery(text, max_length=250, min_length=40, do_sample=False)[0] | |
| return summary["summary_text"] | |
| # Create a Gradio interface | |
| interface = gr.Interface( | |
| fn=summarize, # the function to wrap | |
| inputs=gr.Textbox(lines=20, label="Text to Summarize"), | |
| outputs=gr.Textbox(label="Summary") | |
| ) | |
| # Launch the interface | |
| interface.launch() |