Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,92 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
pipe = pipeline("summarization", model="Gabriel/bart-base-cnn-xsum-swe")
|
5 |
|
6 |
-
def
|
7 |
print(in_text)
|
8 |
answer = pipe(in_text, num_beams=5 ,min_length=20, max_length=120)
|
9 |
print(answer)
|
10 |
return answer[0]["summary_text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
with gr.Blocks() as demo:
|
13 |
-
|
14 |
-
|
15 |
-
with gr.
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import pandas as pd
|
4 |
+
import json
|
5 |
|
6 |
pipe = pipeline("summarization", model="Gabriel/bart-base-cnn-xsum-swe")
|
7 |
|
8 |
+
def generate(in_text):
|
9 |
print(in_text)
|
10 |
answer = pipe(in_text, num_beams=5 ,min_length=20, max_length=120)
|
11 |
print(answer)
|
12 |
return answer[0]["summary_text"]
|
13 |
+
|
14 |
+
def update_history(df, in_text, gen_text ,generation_type, parameters):
|
15 |
+
# get rid of first seed phrase
|
16 |
+
new_row = [{"In_text": in_text,
|
17 |
+
"Gen_text": gen_text,
|
18 |
+
"Generation Type": generation_type,
|
19 |
+
"Parameters": json.dumps(parameters)}]
|
20 |
+
return pd.concat([df, pd.DataFrame(new_row)])
|
21 |
+
|
22 |
+
def generate_transformer(in_text, num_beams ,history):
|
23 |
+
gen_text= generate(in_text)
|
24 |
+
return gen_text, update_history(history, in_text, gen_text, "Transformer", {"num_beams": num_beams})
|
25 |
+
|
26 |
|
27 |
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("""# Summarization Engine!""")
|
29 |
+
|
30 |
+
with gr.Accordion("See Details", open=False):
|
31 |
+
gr.Markdown("lorem ipsum")
|
32 |
+
|
33 |
+
|
34 |
+
with gr.Tabs():
|
35 |
+
with gr.TabItem("Transformer Generation"):
|
36 |
+
gr.Markdown(
|
37 |
+
"""The default parameters for distilgpt2 work well to generate moves. Use this tab as
|
38 |
+
a baseline for your experiments.""")
|
39 |
+
|
40 |
+
with gr.Row():
|
41 |
+
with gr.Column(scale=4):
|
42 |
+
text_baseline_transformer= gr.Textbox(lines=4,label="Input Text", placeholder="hej hej",)
|
43 |
+
with gr.Column(scale=3):
|
44 |
+
with gr.Row():
|
45 |
+
num_beams = gr.Slider(minimum=2, maximum=10, value=2, step=1, label="Number of Beams2")
|
46 |
+
output_basline_transformer = gr.Textbox(label="Output Text")
|
47 |
+
transformer_button = gr.Button("Summarize!")
|
48 |
+
|
49 |
+
# with gr.TabItem("Strong Baseline"):
|
50 |
+
# gr.Markdown(
|
51 |
+
# """The default parameters for distilgpt2 work well to generate moves. Use this tab as
|
52 |
+
# a baseline for your experiments.""")
|
53 |
+
# with gr.Row():
|
54 |
+
# with gr.Column(scale=4):
|
55 |
+
# text_baseline= gr.Textbox(lines=4,label="Input Text", placeholder="hej hej",)
|
56 |
+
# with gr.Column(scale=3):
|
57 |
+
# with gr.Row():
|
58 |
+
# num_beams2 = gr.Slider(minimum=2, maximum=10, value=2, step=1, label="Number of Beams2")
|
59 |
+
# num_beams3 = gr.Slider(minimum=2, maximum=10, value=2, step=1, label="Number of Beams3")
|
60 |
+
# output_basline = gr.Textbox(label="Output Text")
|
61 |
+
# baseline_button = gr.Button("Summarize!")
|
62 |
+
|
63 |
+
# with gr.TabItem("LexRank"):
|
64 |
+
# gr.Markdown(
|
65 |
+
# """The default parameters for distilgpt2 work well to generate moves. Use this tab as
|
66 |
+
# a baseline for your experiments.""")
|
67 |
+
# with gr.Row():
|
68 |
+
# label="Number of Beams")
|
69 |
+
# text_baseline= gr.Textbox(label="Input Text", placeholder="hej hej",)
|
70 |
+
# output_basline = gr.Textbox(label="Output Text")
|
71 |
+
# baseline_button = gr.Button("Summarize!")
|
72 |
+
|
73 |
+
gr.Examples([["hi", 5]], [text_baseline_transformer, num_beams])
|
74 |
+
|
75 |
+
with gr.Box():
|
76 |
+
gr.Markdown("<h3> Generation History <h3>")
|
77 |
+
# Displays a dataframe with the history of moves generated, with parameters
|
78 |
+
history = gr.Dataframe(headers=["In_text", "Gen_text", "Generation Type", "Parameters"], overflow_row_behaviour="show_ends", wrap=True)
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
with gr.Box():
|
83 |
+
gr.Markdown("<h3>How did you make this?<h3>")
|
84 |
+
# gr.Markdown("""hej bottom.""")
|
85 |
+
transformer_button.click(generate_transformer, inputs=[text_baseline_transformer, num_beams ,history], outputs=[output_basline_transformer , history] )
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
# baseline_button.click(generate_transformer, inputs=[text_baseline, num_beams2 ,history], outputs=[output_basline,history] )
|
90 |
+
|
91 |
+
|
92 |
+
demo.launch()
|