Spaces:
Sleeping
Sleeping
Download app.py from Master0fNone/TextSummarizationHW: direct link, hf CLI and curl.
- Browser
- Download file 796 Bytes
-
https://huggingface.co/spaces/Master0fNone/TextSummarizationHW/resolve/main/app.py
- Command line
-
hf download hf://spaces/Master0fNone/TextSummarizationHW/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Master0fNone/TextSummarizationHW/resolve/main/app.py
796 Bytes
| # 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() |