Spaces:
Running
Running
Download app.py from sapnaju/Text_Summarizer: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/sapnaju/Text_Summarizer/resolve/main/app.py
- Command line
-
hf download hf://spaces/sapnaju/Text_Summarizer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sapnaju/Text_Summarizer/resolve/main/app.py
1.25 kB
| import torch | |
| import gradio as gr | |
| from transformers import pipeline | |
| model_name = "sshleifer/distilbart-cnn-6-6" | |
| print("Loading summarization model...") | |
| text_summary = pipeline( | |
| "summarization", | |
| model=model_name | |
| ) | |
| print("Model loaded successfully!") | |
| text = """ | |
| #Artificial intelligence is transforming many industries. | |
| #Machine learning allows computers to learn patterns from data. | |
| #Natural language processing helps computers understand and generate | |
| #human language. These technologies are used in chatbots, | |
| #recommendation systems, and text summarization applications.""" | |
| result = text_summary( | |
| text, | |
| max_length=55, | |
| min_length=15, | |
| do_sample=False | |
| ) | |
| print("Summary:") | |
| print(result[0]["summary_text"]) | |
| def summary_grd(input): | |
| output = text_summary(input) | |
| return output[0]["summary_text"] | |
| gr.close_all() | |
| # demo = gr.Interface (fn=summary_grd, inputs = "text",outputs="text") | |
| demo = gr.Interface(fn = summary_grd,inputs =[ gr.Textbox(label = "Input text to summarize",lines=6)], | |
| outputs = [gr.Textbox(label = "Summarize",lines=6)], | |
| title="GenAI Project 1 Summarizer", | |
| description="This application will be used to summarize text") | |
| demo.launch() | |