Spaces:
Sleeping
Sleeping
| # Imports | |
| import gradio as gr | |
| from transformers import AutoModel, AutoProcessor | |
| import torch | |
| import requests | |
| from PIL import Image | |
| from io import BytesIO | |
| from transformers import pipeline | |
| # Import a specific model | |
| model_name = "facebook/bart-large-cnn" | |
| # Create a summarization pipeline with Facebook Bart | |
| summarizer = pipeline("summarization", model=model_name) | |
| # Define a function that takes input and returns summary | |
| def summarize(input_text): | |
| summary = summarizer(input_text, max_length=100, min_length=10, do_sample=False) | |
| return summary[0]["summary_text"] | |
| # Create a Gradio interface | |
| interface = gr.Interface( | |
| fn=summarize, # the function to wrap | |
| inputs=gr.Textbox(lines=10, label="Input Text"), | |
| outputs=gr.Textbox(label="Summary") | |
| ) | |
| # Launch the interface | |
| interface.launch() |