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