JLW commited on
Commit
c40f599
·
1 Parent(s): 278f4c3

Change to tabs layout

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