Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,59 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
import gradio as gr
|
3 |
+
from transformers import AutoModelWithLMHead, AutoTokenizer
|
4 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
+
from transformers import pipeline
|
6 |
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("sumedh/t5-base-amazonreviews")
|
8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("sumedh/t5-base-amazonreviews")
|
9 |
|
10 |
+
|
11 |
+
def summarize_conversation(conversation, slider_value):
|
12 |
+
|
13 |
+
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
14 |
+
summarized_conversation = summarizer(conversation.strip(), min_length=int(slider_value))
|
15 |
+
|
16 |
+
return summarized_conversation[0]["summary_text"]
|
17 |
+
|
18 |
+
|
19 |
+
def change_textbox(choice):
|
20 |
+
|
21 |
+
with open('examples.json') as json_file:
|
22 |
+
examples = json.load(json_file)
|
23 |
+
|
24 |
+
if choice == "Customer Dialog AmazonHelp":
|
25 |
+
return gr.update(lines=8, visible=True, value=str(examples["dialog_1"]))
|
26 |
+
elif choice == "Customer Dialog XBoxSupport":
|
27 |
+
return gr.update(lines=8, visible=True, value=str(examples["dialog_2"]))
|
28 |
+
elif choice == "Customer Dialog AppleSupport":
|
29 |
+
return gr.update(lines=8, visible=True, value=str(examples["dialog_3"]))
|
30 |
+
elif choice == "Fridge: Ice maker is not working":
|
31 |
+
return gr.update(lines=8, visible=True, value=str(examples["text_ice_maker_not_working"]))
|
32 |
+
elif choice == "Troubleshooting Iphone":
|
33 |
+
return gr.update(lines=8, visible=True, value=str(examples["text_iphone_troubleshooting"]))
|
34 |
+
else:
|
35 |
+
return gr.update(lines=8, visible=True, value="")
|
36 |
+
|
37 |
+
|
38 |
+
with gr.Blocks() as demo:
|
39 |
+
|
40 |
+
radio = gr.Radio(
|
41 |
+
["Free Text Input", "Customer Dialog AmazonHelp", "Customer Dialog XBoxSupport", "Customer Dialog AppleSupport", "Fridge: Ice maker is not working", "Troubleshooting Iphone"], label="What should the AI summarize?"
|
42 |
+
)
|
43 |
+
text = gr.Textbox(lines=2, interactive=True, placeholder="Your text here...")
|
44 |
+
output = gr.Textbox(lines=2, interactive=True, placeholder="Your result here...")
|
45 |
+
|
46 |
+
radio.change(fn=change_textbox, inputs=radio, outputs=text)
|
47 |
+
slider_value = gr.Slider(minimum=20, maximum=142, value=42, randomize=False, label="Minimal length of summary.")
|
48 |
+
button_clear = gr.Button("Clear")
|
49 |
+
button_1 = gr.Button("Summarize")
|
50 |
+
|
51 |
+
button_1.click(fn=summarize_conversation, inputs=[text, slider_value], outputs=output)
|
52 |
+
|
53 |
+
button_clear.click(
|
54 |
+
lambda: [c.update(value=None) for c in [text, output]],
|
55 |
+
inputs=[],
|
56 |
+
outputs=[text, output]
|
57 |
+
)
|
58 |
+
|
59 |
+
demo.launch(share=True)
|