Change to tabs layout
Browse files- app.py +148 -150
- videos/tempfile.mp4 +2 -2
app.py
CHANGED
|
@@ -346,157 +346,155 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
|
|
| 346 |
translate_to_state = gr.State(TRANSLATE_TO_DEFAULT)
|
| 347 |
literary_style_state = gr.State(LITERARY_STYLE_DEFAULT)
|
| 348 |
|
| 349 |
-
with gr.
|
| 350 |
-
with gr.
|
| 351 |
-
gr.
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
with gr.
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
inputs=[joy_level_radio, joy_level_state],
|
| 439 |
-
outputs=[joy_level_state])
|
| 440 |
-
|
| 441 |
-
trust_level_radio = gr.Radio(label="Trust level:",
|
| 442 |
-
choices=[EMOTION_DEFAULT, "Acceptance", "Trust", "Admiration"],
|
| 443 |
-
value=EMOTION_DEFAULT)
|
| 444 |
-
trust_level_radio.change(update_foo,
|
| 445 |
-
inputs=[trust_level_radio, trust_level_state],
|
| 446 |
-
outputs=[trust_level_state])
|
| 447 |
-
|
| 448 |
-
fear_level_radio = gr.Radio(label="Fear level:",
|
| 449 |
-
choices=[EMOTION_DEFAULT, "Apprehension", "Fear", "Terror"],
|
| 450 |
value=EMOTION_DEFAULT)
|
| 451 |
-
|
| 452 |
-
inputs=[
|
| 453 |
-
outputs=[
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
|
| 501 |
gr.HTML("""
|
| 502 |
This application demonstrates a conversational agent implemented with OpenAI GPT-3.5 and LangChain.
|
|
|
|
| 346 |
translate_to_state = gr.State(TRANSLATE_TO_DEFAULT)
|
| 347 |
literary_style_state = gr.State(LITERARY_STYLE_DEFAULT)
|
| 348 |
|
| 349 |
+
with gr.Tab("Chat"):
|
| 350 |
+
with gr.Row():
|
| 351 |
+
with gr.Column():
|
| 352 |
+
gr.Markdown("<h4><center>Conversational Agent using GPT-3.5 & LangChain</center></h4>")
|
| 353 |
+
|
| 354 |
+
openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
|
| 355 |
+
show_label=False, lines=1, type='password')
|
| 356 |
+
|
| 357 |
+
with gr.Row():
|
| 358 |
+
with gr.Column(scale=1, min_width=240):
|
| 359 |
+
my_file = gr.File(label="Upload a file", type="file", visible=False)
|
| 360 |
+
tmp_file = gr.File("videos/Masahiro.mp4", visible=False)
|
| 361 |
+
tmp_file_url = "/file=" + tmp_file.value['name']
|
| 362 |
+
htm_video = f'<video width="256" height="256" autoplay muted loop><source src={tmp_file_url} type="video/mp4" poster="Masahiro.png"></video>'
|
| 363 |
+
video_html = gr.HTML(htm_video)
|
| 364 |
+
|
| 365 |
+
trace_chain_cb = gr.Checkbox(label="Show chain", value=False)
|
| 366 |
+
trace_chain_cb.change(update_foo, inputs=[trace_chain_cb, trace_chain_state],
|
| 367 |
+
outputs=[trace_chain_state])
|
| 368 |
+
|
| 369 |
+
with gr.Column(scale=3):
|
| 370 |
+
chatbot = gr.Chatbot()
|
| 371 |
+
|
| 372 |
+
with gr.Row():
|
| 373 |
+
message = gr.Textbox(label="What's on your mind??",
|
| 374 |
+
placeholder="What's the answer to life, the universe, and everything?",
|
| 375 |
+
lines=1)
|
| 376 |
+
submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
|
| 377 |
+
|
| 378 |
+
# UNCOMMENT TO USE WHISPER
|
| 379 |
+
# with gr.Row():
|
| 380 |
+
# audio_comp = gr.Microphone(source="microphone", type="filepath", label="Just say it!",
|
| 381 |
+
# interactive=True, streaming=False)
|
| 382 |
+
# audio_comp.change(transcribe, inputs=[audio_comp], outputs=[message])
|
| 383 |
+
|
| 384 |
+
gr.Examples(
|
| 385 |
+
examples=["How many people live in Canada?",
|
| 386 |
+
"What is 2 to the 30th power?",
|
| 387 |
+
"How much did it rain in SF today?",
|
| 388 |
+
"Get me information about the movie 'Avatar'",
|
| 389 |
+
"What are the top tech headlines in the US?",
|
| 390 |
+
"On the desk, you see two blue booklets, two purple booklets, and two yellow pairs of sunglasses - "
|
| 391 |
+
"if I remove all the pairs of sunglasses from the desk, how many purple items remain on it?"],
|
| 392 |
+
inputs=message
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
with gr.Tab("Tools"):
|
| 396 |
+
tools_cb_group = gr.CheckboxGroup(label="Tools:", choices=TOOLS_LIST,
|
| 397 |
+
value=TOOLS_DEFAULT_LIST)
|
| 398 |
+
tools_cb_group.change(update_selected_tools,
|
| 399 |
+
inputs=[tools_cb_group, tools_list_state, llm_state],
|
| 400 |
+
outputs=[tools_list_state, llm_state, chain_state, express_chain_state])
|
| 401 |
+
|
| 402 |
+
with gr.Tab("Formality"):
|
| 403 |
+
formality_radio = gr.Radio(label="Formality:",
|
| 404 |
+
choices=[FORMALITY_DEFAULT, "Casual", "Polite", "Honorific"],
|
| 405 |
+
value=FORMALITY_DEFAULT)
|
| 406 |
+
formality_radio.change(update_foo,
|
| 407 |
+
inputs=[formality_radio, formality_state],
|
| 408 |
+
outputs=[formality_state])
|
| 409 |
+
|
| 410 |
+
with gr.Tab("Translate to"):
|
| 411 |
+
translate_to_radio = gr.Radio(label="Translate to:", choices=[
|
| 412 |
+
TRANSLATE_TO_DEFAULT, "Arabic", "British English", "Chinese (Simplified)", "Chinese (Traditional)",
|
| 413 |
+
"Czech", "Danish", "Dutch", "English", "Finnish", "French", "German",
|
| 414 |
+
"Greek", "Hebrew", "Hindi", "Hungarian", "Indonesian", "Italian", "Japanese",
|
| 415 |
+
"Korean", "Norwegian", "Old English", "Polish", "Portuguese", "Romanian",
|
| 416 |
+
"Russian", "Spanish", "Swedish", "Thai", "Turkish",
|
| 417 |
+
"Vietnamese",
|
| 418 |
+
"emojis", "Gen Z slang", "how the stereotypical Karen would say it", "Klingon",
|
| 419 |
+
"Pirate", "Strange Planet expospeak technical talk", "Yoda"],
|
| 420 |
+
value=TRANSLATE_TO_DEFAULT)
|
| 421 |
+
|
| 422 |
+
translate_to_radio.change(update_foo,
|
| 423 |
+
inputs=[translate_to_radio, translate_to_state],
|
| 424 |
+
outputs=[translate_to_state])
|
| 425 |
+
|
| 426 |
+
with gr.Tab("Lit style"):
|
| 427 |
+
literary_style_radio = gr.Radio(label="Literary style:", choices=[
|
| 428 |
+
LITERARY_STYLE_DEFAULT, "Poetry", "Haiku", "Limerick", "Joke", "Knock-knock"],
|
| 429 |
+
value=LITERARY_STYLE_DEFAULT)
|
| 430 |
+
|
| 431 |
+
literary_style_radio.change(update_foo,
|
| 432 |
+
inputs=[literary_style_radio, literary_style_state],
|
| 433 |
+
outputs=[literary_style_state])
|
| 434 |
+
|
| 435 |
+
with gr.Tab("Emotions"):
|
| 436 |
+
anticipation_level_radio = gr.Radio(label="Anticipation level:",
|
| 437 |
+
choices=[EMOTION_DEFAULT, "Interest", "Anticipation", "Vigilance"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
value=EMOTION_DEFAULT)
|
| 439 |
+
anticipation_level_radio.change(update_foo,
|
| 440 |
+
inputs=[anticipation_level_radio, anticipation_level_state],
|
| 441 |
+
outputs=[anticipation_level_state])
|
| 442 |
+
|
| 443 |
+
joy_level_radio = gr.Radio(label="Joy level:",
|
| 444 |
+
choices=[EMOTION_DEFAULT, "Serenity", "Joy", "Ecstasy"],
|
| 445 |
+
value=EMOTION_DEFAULT)
|
| 446 |
+
joy_level_radio.change(update_foo,
|
| 447 |
+
inputs=[joy_level_radio, joy_level_state],
|
| 448 |
+
outputs=[joy_level_state])
|
| 449 |
+
|
| 450 |
+
trust_level_radio = gr.Radio(label="Trust level:",
|
| 451 |
+
choices=[EMOTION_DEFAULT, "Acceptance", "Trust", "Admiration"],
|
| 452 |
+
value=EMOTION_DEFAULT)
|
| 453 |
+
trust_level_radio.change(update_foo,
|
| 454 |
+
inputs=[trust_level_radio, trust_level_state],
|
| 455 |
+
outputs=[trust_level_state])
|
| 456 |
+
|
| 457 |
+
fear_level_radio = gr.Radio(label="Fear level:",
|
| 458 |
+
choices=[EMOTION_DEFAULT, "Apprehension", "Fear", "Terror"],
|
| 459 |
+
value=EMOTION_DEFAULT)
|
| 460 |
+
fear_level_radio.change(update_foo,
|
| 461 |
+
inputs=[fear_level_radio, fear_level_state],
|
| 462 |
+
outputs=[fear_level_state])
|
| 463 |
+
|
| 464 |
+
surprise_level_radio = gr.Radio(label="Surprise level:",
|
| 465 |
+
choices=[EMOTION_DEFAULT, "Distraction", "Surprise", "Amazement"],
|
| 466 |
+
value=EMOTION_DEFAULT)
|
| 467 |
+
surprise_level_radio.change(update_foo,
|
| 468 |
+
inputs=[surprise_level_radio, surprise_level_state],
|
| 469 |
+
outputs=[surprise_level_state])
|
| 470 |
+
|
| 471 |
+
sadness_level_radio = gr.Radio(label="Sadness level:",
|
| 472 |
+
choices=[EMOTION_DEFAULT, "Pensiveness", "Sadness", "Grief"],
|
| 473 |
+
value=EMOTION_DEFAULT)
|
| 474 |
+
sadness_level_radio.change(update_foo,
|
| 475 |
+
inputs=[sadness_level_radio, sadness_level_state],
|
| 476 |
+
outputs=[sadness_level_state])
|
| 477 |
+
|
| 478 |
+
disgust_level_radio = gr.Radio(label="Disgust level:",
|
| 479 |
+
choices=[EMOTION_DEFAULT, "Boredom", "Disgust", "Loathing"],
|
| 480 |
+
value=EMOTION_DEFAULT)
|
| 481 |
+
disgust_level_radio.change(update_foo,
|
| 482 |
+
inputs=[disgust_level_radio, disgust_level_state],
|
| 483 |
+
outputs=[disgust_level_state])
|
| 484 |
+
|
| 485 |
+
anger_level_radio = gr.Radio(label="Anger level:",
|
| 486 |
+
choices=[EMOTION_DEFAULT, "Annoyance", "Anger", "Rage"],
|
| 487 |
+
value=EMOTION_DEFAULT)
|
| 488 |
+
anger_level_radio.change(update_foo,
|
| 489 |
+
inputs=[anger_level_radio, anger_level_state],
|
| 490 |
+
outputs=[anger_level_state])
|
| 491 |
+
|
| 492 |
+
with gr.Tab("Max words"):
|
| 493 |
+
num_words_slider = gr.Slider(label="Max number of words to generate (0 for don't care)",
|
| 494 |
+
value=NUM_WORDS_DEFAULT, minimum=0, maximum=100, step=10)
|
| 495 |
+
num_words_slider.change(update_foo,
|
| 496 |
+
inputs=[num_words_slider, num_words_state],
|
| 497 |
+
outputs=[num_words_state])
|
| 498 |
|
| 499 |
gr.HTML("""
|
| 500 |
This application demonstrates a conversational agent implemented with OpenAI GPT-3.5 and LangChain.
|
videos/tempfile.mp4
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ea3c828fcd3a6a6a78d6aa9f7c6d1eaaf6b94fc9f4ea84bcd2472fb2f45d8800
|
| 3 |
+
size 85993
|