Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
def summarize_article(article, model_name, max_length, temperature, top_k, top_p):
|
5 |
+
summarizer = pipeline("summarization", model=model_name)
|
6 |
+
top_k = int(round(top_k))
|
7 |
+
max_length = int(round(max_length))
|
8 |
+
summary = summarizer(article, max_length=max_length, min_length=30, do_sample=True, temperature=temperature, top_k=top_k, top_p=top_p)
|
9 |
+
return summary[0]['summary_text']
|
10 |
+
|
11 |
+
iface = gr.Interface(
|
12 |
+
fn=summarize_article,
|
13 |
+
inputs=[
|
14 |
+
"text",
|
15 |
+
gr.inputs.Dropdown(["Falconsai/text_summarization", "Other Models..."], label="Select Model"),
|
16 |
+
gr.inputs.Number(default=100, label="Max-Length"),
|
17 |
+
gr.inputs.Slider(minimum=0.1, maximum=1.999, default=0.7, label="Temperature"),
|
18 |
+
gr.inputs.Number(default=50, label="Top-k"),
|
19 |
+
gr.inputs.Number(default=0.9, label="Top-p")
|
20 |
+
],
|
21 |
+
outputs="text",
|
22 |
+
title="Text Summarization with Hyperparameters",
|
23 |
+
description="Enter an article, select a model, and adjust hyperparameters for summarization."
|
24 |
+
)
|
25 |
+
|
26 |
+
iface.launch(debug=True)
|