JLW commited on
Commit
f4fc33c
·
1 Parent(s): fa3649e

Display down for maintenance message

Browse files
Files changed (1) hide show
  1. app.py +192 -188
app.py CHANGED
@@ -417,193 +417,197 @@ with gr.Blocks(css=".gradio-container {background-color: lightgray}") as block:
417
  translate_to_state = gr.State(TRANSLATE_TO_DEFAULT)
418
  literary_style_state = gr.State(LITERARY_STYLE_DEFAULT)
419
 
420
- with gr.Tab("Chat"):
421
- with gr.Row():
422
- with gr.Column():
423
- gr.Markdown("<h4><center>Conversational Agent using GPT-3.5 & LangChain</center></h4>")
424
-
425
- openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
426
- show_label=False, lines=1, type='password')
427
-
428
- with gr.Row():
429
- with gr.Column(scale=1, min_width=100, visible=False):
430
- my_file = gr.File(label="Upload a file", type="file", visible=False)
431
- tmp_file = gr.File("videos/Masahiro.mp4", visible=False)
432
- tmp_file_url = "/file=" + tmp_file.value['name']
433
- htm_video = f'<video width="256" height="256" autoplay muted loop><source src={tmp_file_url} type="video/mp4" poster="Masahiro.png"></video>'
434
- video_html = gr.HTML(htm_video)
435
-
436
- # my_aud_file = gr.File(label="Audio file", type="file", visible=True)
437
- tmp_aud_file = gr.File("audios/tempfile.mp3", visible=False)
438
- tmp_aud_file_url = "/file=" + tmp_aud_file.value['name']
439
- htm_audio = f'<audio><source src={tmp_aud_file_url} type="audio/mp3"></audio>'
440
- audio_html = gr.HTML(htm_audio)
441
-
442
- with gr.Column(scale=3):
443
- chatbot = gr.Chatbot()
444
-
445
- with gr.Row():
446
- message = gr.Textbox(label="What's on your mind??",
447
- placeholder="What's the answer to life, the universe, and everything?",
448
- lines=1)
449
- submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
450
-
451
- # UNCOMMENT TO USE WHISPER
452
- # with gr.Row():
453
- # audio_comp = gr.Microphone(source="microphone", type="filepath", label="Just say it!",
454
- # interactive=True, streaming=False)
455
- # audio_comp.change(transcribe, inputs=[audio_comp], outputs=[message])
456
-
457
- gr.Examples(
458
- examples=["How many people live in Canada?",
459
- "What is 2 to the 30th power?",
460
- "How much did it rain in SF today?",
461
- "Get me information about the movie 'Avatar'",
462
- "What are the top tech headlines in the US?",
463
- "On the desk, you see two blue booklets, two purple booklets, and two yellow pairs of sunglasses - "
464
- "if I remove all the pairs of sunglasses from the desk, how many purple items remain on it?"],
465
- inputs=message
466
- )
467
-
468
- with gr.Tab("Settings"):
469
- tools_cb_group = gr.CheckboxGroup(label="Tools:", choices=TOOLS_LIST,
470
- value=TOOLS_DEFAULT_LIST)
471
- tools_cb_group.change(update_selected_tools,
472
- inputs=[tools_cb_group, tools_list_state, llm_state],
473
- outputs=[tools_list_state, llm_state, chain_state, express_chain_state])
474
-
475
- trace_chain_cb = gr.Checkbox(label="Show reasoning chain in chat bubble", value=False)
476
- trace_chain_cb.change(update_foo, inputs=[trace_chain_cb, trace_chain_state],
477
- outputs=[trace_chain_state])
478
-
479
- speak_text_cb = gr.Checkbox(label="Speak text from agent", value=False)
480
- speak_text_cb.change(update_foo, inputs=[speak_text_cb, speak_text_state],
481
- outputs=[speak_text_state])
482
-
483
- with gr.Tab("Formality"):
484
- formality_radio = gr.Radio(label="Formality:",
485
- choices=[FORMALITY_DEFAULT, "Casual", "Polite", "Honorific"],
486
- value=FORMALITY_DEFAULT)
487
- formality_radio.change(update_foo,
488
- inputs=[formality_radio, formality_state],
489
- outputs=[formality_state])
490
-
491
- with gr.Tab("Translate to"):
492
- translate_to_radio = gr.Radio(label="Translate to:", choices=[
493
- TRANSLATE_TO_DEFAULT, "Arabic", "Arabic (Gulf)", "Catalan", "Chinese (Cantonese)", "Chinese (Mandarin)",
494
- "Danish", "Dutch", "English (Australian)", "English (British)", "English (Indian)", "English (New Zealand)",
495
- "English (South African)", "English (US)", "English (Welsh)", "Finnish", "French", "French (Canadian)",
496
- "German", "German (Austrian)", "Hindi", "Icelandic", "Italian", "Japanese", "Korean", "Norwegian", "Polish",
497
- "Portuguese (Brazilian)", "Portuguese (European)", "Romanian", "Russian", "Spanish (European)",
498
- "Spanish (Mexican)", "Spanish (US)", "Swedish", "Turkish", "Ukrainian", "Welsh",
499
- "emojis", "Gen Z slang", "how the stereotypical Karen would say it", "Klingon",
500
- "Pirate", "Strange Planet expospeak technical talk", "Yoda"],
501
- value=TRANSLATE_TO_DEFAULT)
502
-
503
- translate_to_radio.change(update_foo,
504
- inputs=[translate_to_radio, translate_to_state],
505
- outputs=[translate_to_state])
506
-
507
- with gr.Tab("Lit style"):
508
- literary_style_radio = gr.Radio(label="Literary style:", choices=[
509
- LITERARY_STYLE_DEFAULT, "Prose", "Summary", "Outline", "Bullets", "Poetry", "Haiku", "Limerick", "Joke",
510
- "Knock-knock"],
511
- value=LITERARY_STYLE_DEFAULT)
512
-
513
- literary_style_radio.change(update_foo,
514
- inputs=[literary_style_radio, literary_style_state],
515
- outputs=[literary_style_state])
516
-
517
- with gr.Tab("Emotions"):
518
- anticipation_level_radio = gr.Radio(label="Anticipation level:",
519
- choices=[EMOTION_DEFAULT, "Interest", "Anticipation", "Vigilance"],
520
- value=EMOTION_DEFAULT)
521
- anticipation_level_radio.change(update_foo,
522
- inputs=[anticipation_level_radio, anticipation_level_state],
523
- outputs=[anticipation_level_state])
524
-
525
- joy_level_radio = gr.Radio(label="Joy level:",
526
- choices=[EMOTION_DEFAULT, "Serenity", "Joy", "Ecstasy"],
527
- value=EMOTION_DEFAULT)
528
- joy_level_radio.change(update_foo,
529
- inputs=[joy_level_radio, joy_level_state],
530
- outputs=[joy_level_state])
531
-
532
- trust_level_radio = gr.Radio(label="Trust level:",
533
- choices=[EMOTION_DEFAULT, "Acceptance", "Trust", "Admiration"],
534
- value=EMOTION_DEFAULT)
535
- trust_level_radio.change(update_foo,
536
- inputs=[trust_level_radio, trust_level_state],
537
- outputs=[trust_level_state])
538
-
539
- fear_level_radio = gr.Radio(label="Fear level:",
540
- choices=[EMOTION_DEFAULT, "Apprehension", "Fear", "Terror"],
541
- value=EMOTION_DEFAULT)
542
- fear_level_radio.change(update_foo,
543
- inputs=[fear_level_radio, fear_level_state],
544
- outputs=[fear_level_state])
545
-
546
- surprise_level_radio = gr.Radio(label="Surprise level:",
547
- choices=[EMOTION_DEFAULT, "Distraction", "Surprise", "Amazement"],
548
- value=EMOTION_DEFAULT)
549
- surprise_level_radio.change(update_foo,
550
- inputs=[surprise_level_radio, surprise_level_state],
551
- outputs=[surprise_level_state])
552
-
553
- sadness_level_radio = gr.Radio(label="Sadness level:",
554
- choices=[EMOTION_DEFAULT, "Pensiveness", "Sadness", "Grief"],
555
- value=EMOTION_DEFAULT)
556
- sadness_level_radio.change(update_foo,
557
- inputs=[sadness_level_radio, sadness_level_state],
558
- outputs=[sadness_level_state])
559
-
560
- disgust_level_radio = gr.Radio(label="Disgust level:",
561
- choices=[EMOTION_DEFAULT, "Boredom", "Disgust", "Loathing"],
562
- value=EMOTION_DEFAULT)
563
- disgust_level_radio.change(update_foo,
564
- inputs=[disgust_level_radio, disgust_level_state],
565
- outputs=[disgust_level_state])
566
-
567
- anger_level_radio = gr.Radio(label="Anger level:",
568
- choices=[EMOTION_DEFAULT, "Annoyance", "Anger", "Rage"],
569
- value=EMOTION_DEFAULT)
570
- anger_level_radio.change(update_foo,
571
- inputs=[anger_level_radio, anger_level_state],
572
- outputs=[anger_level_state])
573
-
574
- with gr.Tab("Max words"):
575
- num_words_slider = gr.Slider(label="Max number of words to generate (0 for don't care)",
576
- value=NUM_WORDS_DEFAULT, minimum=0, maximum=MAX_WORDS, step=10)
577
- num_words_slider.change(update_foo,
578
- inputs=[num_words_slider, num_words_state],
579
- outputs=[num_words_state])
580
-
581
- gr.HTML("""
582
- This application demonstrates a conversational agent implemented with OpenAI GPT-3.5 and LangChain.
583
- When necessary, it leverages tools for complex math, searching the internet, and accessing news and weather.
584
- On a desktop, the agent will often speak using using an animated avatar from
585
- <a href='https://exh.ai/'>Ex-Human</a>.""")
586
-
587
- gr.HTML("<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a></center>")
588
-
589
- message.submit(chat, inputs=[message, history_state, chain_state, trace_chain_state, speak_text_state,
590
- express_chain_state, num_words_state, formality_state,
591
- anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
592
- surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
593
- translate_to_state, literary_style_state],
594
- # outputs=[chatbot, history_state, video_html, my_file, message])
595
- outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
596
-
597
- submit.click(chat, inputs=[message, history_state, chain_state, trace_chain_state, speak_text_state,
598
- express_chain_state, num_words_state, formality_state,
599
- anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
600
- surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
601
- translate_to_state, literary_style_state],
602
- # outputs=[chatbot, history_state, video_html, my_file, message])
603
- outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
604
-
605
- openai_api_key_textbox.change(set_openai_api_key,
606
- inputs=[openai_api_key_textbox],
607
- outputs=[chain_state, express_chain_state, llm_state])
 
 
 
 
608
 
609
  block.launch(debug=True)
 
417
  translate_to_state = gr.State(TRANSLATE_TO_DEFAULT)
418
  literary_style_state = gr.State(LITERARY_STYLE_DEFAULT)
419
 
420
+ gr.Markdown("<h4><center>Conversational Agent using GPT-3.5 & LangChain</center></h4>")
421
+ gr.Markdown(
422
+ "<b><i><center>Down while implementing some great feedback gathered from the last few days</center></i></b>")
423
+
424
+ # with gr.Tab("Chat"):
425
+ # with gr.Row():
426
+ # with gr.Column():
427
+ # gr.Markdown("<h4><center>Conversational Agent using GPT-3.5 & LangChain</center></h4>")
428
+ #
429
+ # openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
430
+ # show_label=False, lines=1, type='password')
431
+ #
432
+ # with gr.Row():
433
+ # with gr.Column(scale=1, min_width=100, visible=False):
434
+ # my_file = gr.File(label="Upload a file", type="file", visible=False)
435
+ # tmp_file = gr.File("videos/Masahiro.mp4", visible=False)
436
+ # tmp_file_url = "/file=" + tmp_file.value['name']
437
+ # htm_video = f'<video width="256" height="256" autoplay muted loop><source src={tmp_file_url} type="video/mp4" poster="Masahiro.png"></video>'
438
+ # video_html = gr.HTML(htm_video)
439
+ #
440
+ # # my_aud_file = gr.File(label="Audio file", type="file", visible=True)
441
+ # tmp_aud_file = gr.File("audios/tempfile.mp3", visible=False)
442
+ # tmp_aud_file_url = "/file=" + tmp_aud_file.value['name']
443
+ # htm_audio = f'<audio><source src={tmp_aud_file_url} type="audio/mp3"></audio>'
444
+ # audio_html = gr.HTML(htm_audio)
445
+ #
446
+ # with gr.Column(scale=3):
447
+ # chatbot = gr.Chatbot()
448
+ #
449
+ # with gr.Row():
450
+ # message = gr.Textbox(label="What's on your mind??",
451
+ # placeholder="What's the answer to life, the universe, and everything?",
452
+ # lines=1)
453
+ # submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
454
+ #
455
+ # # UNCOMMENT TO USE WHISPER
456
+ # # with gr.Row():
457
+ # # audio_comp = gr.Microphone(source="microphone", type="filepath", label="Just say it!",
458
+ # # interactive=True, streaming=False)
459
+ # # audio_comp.change(transcribe, inputs=[audio_comp], outputs=[message])
460
+ #
461
+ # gr.Examples(
462
+ # examples=["How many people live in Canada?",
463
+ # "What is 2 to the 30th power?",
464
+ # "How much did it rain in SF today?",
465
+ # "Get me information about the movie 'Avatar'",
466
+ # "What are the top tech headlines in the US?",
467
+ # "On the desk, you see two blue booklets, two purple booklets, and two yellow pairs of sunglasses - "
468
+ # "if I remove all the pairs of sunglasses from the desk, how many purple items remain on it?"],
469
+ # inputs=message
470
+ # )
471
+ #
472
+ # with gr.Tab("Settings"):
473
+ # tools_cb_group = gr.CheckboxGroup(label="Tools:", choices=TOOLS_LIST,
474
+ # value=TOOLS_DEFAULT_LIST)
475
+ # tools_cb_group.change(update_selected_tools,
476
+ # inputs=[tools_cb_group, tools_list_state, llm_state],
477
+ # outputs=[tools_list_state, llm_state, chain_state, express_chain_state])
478
+ #
479
+ # trace_chain_cb = gr.Checkbox(label="Show reasoning chain in chat bubble", value=False)
480
+ # trace_chain_cb.change(update_foo, inputs=[trace_chain_cb, trace_chain_state],
481
+ # outputs=[trace_chain_state])
482
+ #
483
+ # speak_text_cb = gr.Checkbox(label="Speak text from agent", value=False)
484
+ # speak_text_cb.change(update_foo, inputs=[speak_text_cb, speak_text_state],
485
+ # outputs=[speak_text_state])
486
+ #
487
+ # with gr.Tab("Formality"):
488
+ # formality_radio = gr.Radio(label="Formality:",
489
+ # choices=[FORMALITY_DEFAULT, "Casual", "Polite", "Honorific"],
490
+ # value=FORMALITY_DEFAULT)
491
+ # formality_radio.change(update_foo,
492
+ # inputs=[formality_radio, formality_state],
493
+ # outputs=[formality_state])
494
+ #
495
+ # with gr.Tab("Translate to"):
496
+ # translate_to_radio = gr.Radio(label="Translate to:", choices=[
497
+ # TRANSLATE_TO_DEFAULT, "Arabic", "Arabic (Gulf)", "Catalan", "Chinese (Cantonese)", "Chinese (Mandarin)",
498
+ # "Danish", "Dutch", "English (Australian)", "English (British)", "English (Indian)", "English (New Zealand)",
499
+ # "English (South African)", "English (US)", "English (Welsh)", "Finnish", "French", "French (Canadian)",
500
+ # "German", "German (Austrian)", "Hindi", "Icelandic", "Italian", "Japanese", "Korean", "Norwegian", "Polish",
501
+ # "Portuguese (Brazilian)", "Portuguese (European)", "Romanian", "Russian", "Spanish (European)",
502
+ # "Spanish (Mexican)", "Spanish (US)", "Swedish", "Turkish", "Ukrainian", "Welsh",
503
+ # "emojis", "Gen Z slang", "how the stereotypical Karen would say it", "Klingon",
504
+ # "Pirate", "Strange Planet expospeak technical talk", "Yoda"],
505
+ # value=TRANSLATE_TO_DEFAULT)
506
+ #
507
+ # translate_to_radio.change(update_foo,
508
+ # inputs=[translate_to_radio, translate_to_state],
509
+ # outputs=[translate_to_state])
510
+ #
511
+ # with gr.Tab("Lit style"):
512
+ # literary_style_radio = gr.Radio(label="Literary style:", choices=[
513
+ # LITERARY_STYLE_DEFAULT, "Prose", "Summary", "Outline", "Bullets", "Poetry", "Haiku", "Limerick", "Joke",
514
+ # "Knock-knock"],
515
+ # value=LITERARY_STYLE_DEFAULT)
516
+ #
517
+ # literary_style_radio.change(update_foo,
518
+ # inputs=[literary_style_radio, literary_style_state],
519
+ # outputs=[literary_style_state])
520
+ #
521
+ # with gr.Tab("Emotions"):
522
+ # anticipation_level_radio = gr.Radio(label="Anticipation level:",
523
+ # choices=[EMOTION_DEFAULT, "Interest", "Anticipation", "Vigilance"],
524
+ # value=EMOTION_DEFAULT)
525
+ # anticipation_level_radio.change(update_foo,
526
+ # inputs=[anticipation_level_radio, anticipation_level_state],
527
+ # outputs=[anticipation_level_state])
528
+ #
529
+ # joy_level_radio = gr.Radio(label="Joy level:",
530
+ # choices=[EMOTION_DEFAULT, "Serenity", "Joy", "Ecstasy"],
531
+ # value=EMOTION_DEFAULT)
532
+ # joy_level_radio.change(update_foo,
533
+ # inputs=[joy_level_radio, joy_level_state],
534
+ # outputs=[joy_level_state])
535
+ #
536
+ # trust_level_radio = gr.Radio(label="Trust level:",
537
+ # choices=[EMOTION_DEFAULT, "Acceptance", "Trust", "Admiration"],
538
+ # value=EMOTION_DEFAULT)
539
+ # trust_level_radio.change(update_foo,
540
+ # inputs=[trust_level_radio, trust_level_state],
541
+ # outputs=[trust_level_state])
542
+ #
543
+ # fear_level_radio = gr.Radio(label="Fear level:",
544
+ # choices=[EMOTION_DEFAULT, "Apprehension", "Fear", "Terror"],
545
+ # value=EMOTION_DEFAULT)
546
+ # fear_level_radio.change(update_foo,
547
+ # inputs=[fear_level_radio, fear_level_state],
548
+ # outputs=[fear_level_state])
549
+ #
550
+ # surprise_level_radio = gr.Radio(label="Surprise level:",
551
+ # choices=[EMOTION_DEFAULT, "Distraction", "Surprise", "Amazement"],
552
+ # value=EMOTION_DEFAULT)
553
+ # surprise_level_radio.change(update_foo,
554
+ # inputs=[surprise_level_radio, surprise_level_state],
555
+ # outputs=[surprise_level_state])
556
+ #
557
+ # sadness_level_radio = gr.Radio(label="Sadness level:",
558
+ # choices=[EMOTION_DEFAULT, "Pensiveness", "Sadness", "Grief"],
559
+ # value=EMOTION_DEFAULT)
560
+ # sadness_level_radio.change(update_foo,
561
+ # inputs=[sadness_level_radio, sadness_level_state],
562
+ # outputs=[sadness_level_state])
563
+ #
564
+ # disgust_level_radio = gr.Radio(label="Disgust level:",
565
+ # choices=[EMOTION_DEFAULT, "Boredom", "Disgust", "Loathing"],
566
+ # value=EMOTION_DEFAULT)
567
+ # disgust_level_radio.change(update_foo,
568
+ # inputs=[disgust_level_radio, disgust_level_state],
569
+ # outputs=[disgust_level_state])
570
+ #
571
+ # anger_level_radio = gr.Radio(label="Anger level:",
572
+ # choices=[EMOTION_DEFAULT, "Annoyance", "Anger", "Rage"],
573
+ # value=EMOTION_DEFAULT)
574
+ # anger_level_radio.change(update_foo,
575
+ # inputs=[anger_level_radio, anger_level_state],
576
+ # outputs=[anger_level_state])
577
+ #
578
+ # with gr.Tab("Max words"):
579
+ # num_words_slider = gr.Slider(label="Max number of words to generate (0 for don't care)",
580
+ # value=NUM_WORDS_DEFAULT, minimum=0, maximum=MAX_WORDS, step=10)
581
+ # num_words_slider.change(update_foo,
582
+ # inputs=[num_words_slider, num_words_state],
583
+ # outputs=[num_words_state])
584
+ #
585
+ # gr.HTML("""
586
+ # This application demonstrates a conversational agent implemented with OpenAI GPT-3.5 and LangChain.
587
+ # When necessary, it leverages tools for complex math, searching the internet, and accessing news and weather.
588
+ # On a desktop, the agent will often speak using using an animated avatar from
589
+ # <a href='https://exh.ai/'>Ex-Human</a>.""")
590
+ #
591
+ # gr.HTML("<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a></center>")
592
+ #
593
+ # message.submit(chat, inputs=[message, history_state, chain_state, trace_chain_state, speak_text_state,
594
+ # express_chain_state, num_words_state, formality_state,
595
+ # anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
596
+ # surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
597
+ # translate_to_state, literary_style_state],
598
+ # # outputs=[chatbot, history_state, video_html, my_file, message])
599
+ # outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
600
+ #
601
+ # submit.click(chat, inputs=[message, history_state, chain_state, trace_chain_state, speak_text_state,
602
+ # express_chain_state, num_words_state, formality_state,
603
+ # anticipation_level_state, joy_level_state, trust_level_state, fear_level_state,
604
+ # surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
605
+ # translate_to_state, literary_style_state],
606
+ # # outputs=[chatbot, history_state, video_html, my_file, message])
607
+ # outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
608
+ #
609
+ # openai_api_key_textbox.change(set_openai_api_key,
610
+ # inputs=[openai_api_key_textbox],
611
+ # outputs=[chain_state, express_chain_state, llm_state])
612
 
613
  block.launch(debug=True)