Spaces:
Sleeping
Sleeping
root
commited on
Commit
•
c1451f6
1
Parent(s):
fc2865d
add multi model selection and min/max length
Browse files
app.py
CHANGED
@@ -1,12 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
if __name__ == "__main__":
|
12 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
def summarize_aritcle(Article, model_selector, min_length, max_length):
|
5 |
+
summarizer = pipeline("summarization", model=model_selector)
|
6 |
+
return f"{model_selector}: \n {summarizer(Article, max_length=max_length, min_length=min_length, do_sample=False)[0]['summary_text']}"
|
7 |
|
8 |
+
# gradio_app = gr.Interface(fn=greet, inputs="text", outputs="text")
|
9 |
+
model_list = ["facebook/bart-large-cnn", "facebook/bart-large-xsum"]
|
10 |
|
11 |
+
with gr.Blocks() as demo:
|
12 |
+
model_selector = gr.Dropdown(model_list, label="model selection", value=0, show_label=True)
|
13 |
+
|
14 |
+
article = gr.TextArea(label="Article Text")
|
15 |
+
min_length=gr.Number(label="min summary length", value=30)
|
16 |
+
max_length=gr.Number(label="max summary length", value=100)
|
17 |
+
|
18 |
+
summary_text = gr.TextArea(label="Summary Text")
|
19 |
+
run_btn = gr.Button("Do Summarize")
|
20 |
+
run_btn.click(fn=summarize_aritcle, inputs=[article, model_selector, min_length, max_length], outputs=summary_text)
|
21 |
|
22 |
if __name__ == "__main__":
|
23 |
+
demo.launch()
|