Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Model options available for summarization | |
| model_names = ["Falconsai/text_summarization"] | |
| def summarize_article(article, model_name, max_length, temperature, top_k, top_p): | |
| """ Summarize the provided article text using the specified model and hyperparameters. """ | |
| summarizer = pipeline("summarization", model=model_name) | |
| summary = summarizer( | |
| article, | |
| max_length=int(round(max_length)), | |
| min_length=30, | |
| do_sample=True, | |
| temperature=temperature, | |
| top_k=int(round(top_k)), | |
| top_p=top_p | |
| ) | |
| return summary[0]['summary_text'] | |
| # Gradio interface setup | |
| iface = gr.Interface( | |
| fn=summarize_article, | |
| inputs=[ | |
| gr.Textbox(lines=10, placeholder="Enter the article text here..."), | |
| gr.Dropdown(choices=model_names, label="Select Model"), | |
| gr.Slider(minimum=10, maximum=200, step=10, label="Max Length of Summary"), | |
| gr.Slider(minimum=0.1, maximum=2, step=0.1, label="Temperature for Sampling"), | |
| gr.Slider(minimum=1, maximum=100, step=1, label="Top-k"), | |
| gr.Slider(minimum=0.1, maximum=1, step=0.1, label="Top-p") | |
| ], | |
| outputs="text", | |
| title="Text Summarization app by Kulsoom", | |
| description="Adjust the parameters below to summarize the article." | |
| ) | |
| iface.launch(debug=True, share=True) |