Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Model options available for summarization
|
| 5 |
+
model_names = ["Falconsai/text_summarization"]
|
| 6 |
+
|
| 7 |
+
def summarize_article(article, model_name, max_length, temperature, top_k, top_p):
|
| 8 |
+
""" Summarize the provided article text using the specified model and hyperparameters. """
|
| 9 |
+
summarizer = pipeline("summarization", model=model_name)
|
| 10 |
+
summary = summarizer(
|
| 11 |
+
article,
|
| 12 |
+
max_length=int(round(max_length)),
|
| 13 |
+
min_length=30,
|
| 14 |
+
do_sample=True,
|
| 15 |
+
temperature=temperature,
|
| 16 |
+
top_k=int(round(top_k)),
|
| 17 |
+
top_p=top_p
|
| 18 |
+
)
|
| 19 |
+
return summary[0]['summary_text']
|
| 20 |
+
|
| 21 |
+
# Gradio interface setup
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=summarize_article,
|
| 24 |
+
inputs=[
|
| 25 |
+
gr.Textbox(lines=10, placeholder="Enter the article text here..."),
|
| 26 |
+
gr.Dropdown(choices=model_names, label="Select Model"),
|
| 27 |
+
gr.Slider(minimum=10, maximum=200, step=10, label="Max Length of Summary"),
|
| 28 |
+
gr.Slider(minimum=0.1, maximum=2, step=0.1, label="Temperature for Sampling"),
|
| 29 |
+
gr.Slider(minimum=1, maximum=100, step=1, label="Top-k"),
|
| 30 |
+
gr.Slider(minimum=0.1, maximum=1, step=0.1, label="Top-p")
|
| 31 |
+
],
|
| 32 |
+
outputs="text",
|
| 33 |
+
title="Text Summarization",
|
| 34 |
+
description="Adjust the parameters below to summarize the article."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
iface.launch(debug=True, share=True)
|