projekt-rising-ai commited on
Commit
dfc3ca7
·
1 Parent(s): a33252b

Added talking head functionality back in

Browse files
Files changed (1) hide show
  1. app.py +30 -13
app.py CHANGED
@@ -51,7 +51,7 @@ BUG_FOUND_MSG = "Congratulations, you've found a bug in this application!"
51
  AUTH_ERR_MSG = "Please paste your OpenAI key from openai.com to use this application. "
52
  MAX_TOKENS = 512
53
 
54
- LOOPING_TALKING_HEAD = "videos/Masahiro.mp4"
55
  TALKING_HEAD_WIDTH = "192"
56
  MAX_TALKING_HEAD_TEXT_LENGTH = 155
57
 
@@ -502,7 +502,7 @@ def do_html_video_speak(words_to_speak, azure_language):
502
 
503
  headers = {"Authorization": f"Bearer {os.environ['EXHUMAN_API_KEY']}"}
504
  body = {
505
- 'bot_name': 'Masahiro',
506
  'bot_response': words_to_speak,
507
  'azure_voice': azure_voice,
508
  'azure_style': 'friendly',
@@ -521,7 +521,7 @@ def do_html_video_speak(words_to_speak, azure_language):
521
  f.write(response_stream.read())
522
  temp_file = gr.File("videos/tempfile.mp4")
523
  temp_file_url = "/file=" + temp_file.value['name']
524
- html_video = f'<video width={TALKING_HEAD_WIDTH} height={TALKING_HEAD_WIDTH} autoplay><source src={temp_file_url} type="video/mp4" poster="Masahiro.png"></video>'
525
  else:
526
  print('video url unknown')
527
  return html_video, "videos/tempfile.mp4"
@@ -613,6 +613,23 @@ with gr.Blocks(css="css/custom_css.css") as block:
613
  show_label=False, lines=1, type='password', elem_id="gr-component")
614
 
615
  with gr.Row():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
  with gr.Column(scale=7):
617
  chatbot = gr.Chatbot(elem_id="gr-component")
618
 
@@ -634,13 +651,13 @@ with gr.Blocks(css="css/custom_css.css") as block:
634
  trace_chain_cb.change(update_foo, inputs=[trace_chain_cb, trace_chain_state],
635
  outputs=[trace_chain_state])
636
 
637
- # speak_text_cb = gr.Checkbox(label="Speak text from agent", value=False)
638
- # speak_text_cb.change(update_foo, inputs=[speak_text_cb, speak_text_state],
639
- # outputs=[speak_text_state])
640
 
641
- # talking_head_cb = gr.Checkbox(label="Show talking head", value=True)
642
- # talking_head_cb.change(update_talking_head, inputs=[talking_head_cb, talking_head_state],
643
- # outputs=[talking_head_state, video_html])
644
 
645
  # monologue_cb = gr.Checkbox(label="Babel fish mode (translate/restate what you enter, no conversational agent)",
646
  # value=False)
@@ -657,8 +674,8 @@ with gr.Blocks(css="css/custom_css.css") as block:
657
  surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
658
  lang_level_state, translate_to_state, literary_style_state,
659
  qa_chain_state, docsearch_state, use_embeddings_state],
660
- # outputs=[chatbot, history_state, video_html, my_file, audio_html, tmp_aud_file, message])
661
- outputs=[chatbot, history_state, message])
662
  # outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
663
 
664
  submit.click(chat, inputs=[openai_api_key_textbox, message, history_state, chain_state, trace_chain_state,
@@ -668,8 +685,8 @@ with gr.Blocks(css="css/custom_css.css") as block:
668
  surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
669
  lang_level_state, translate_to_state, literary_style_state,
670
  qa_chain_state, docsearch_state, use_embeddings_state],
671
- # outputs=[chatbot, history_state, video_html, my_file, audio_html, tmp_aud_file, message])
672
- outputs=[chatbot, history_state, message])
673
  # outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
674
 
675
  openai_api_key_textbox.change(set_openai_api_key,
 
51
  AUTH_ERR_MSG = "Please paste your OpenAI key from openai.com to use this application. "
52
  MAX_TOKENS = 512
53
 
54
+ LOOPING_TALKING_HEAD = "videos/Marc.mp4"
55
  TALKING_HEAD_WIDTH = "192"
56
  MAX_TALKING_HEAD_TEXT_LENGTH = 155
57
 
 
502
 
503
  headers = {"Authorization": f"Bearer {os.environ['EXHUMAN_API_KEY']}"}
504
  body = {
505
+ 'bot_name': 'Marc',
506
  'bot_response': words_to_speak,
507
  'azure_voice': azure_voice,
508
  'azure_style': 'friendly',
 
521
  f.write(response_stream.read())
522
  temp_file = gr.File("videos/tempfile.mp4")
523
  temp_file_url = "/file=" + temp_file.value['name']
524
+ html_video = f'<video width={TALKING_HEAD_WIDTH} height={TALKING_HEAD_WIDTH} autoplay><source src={temp_file_url} type="video/mp4" poster="Marc.png"></video>'
525
  else:
526
  print('video url unknown')
527
  return html_video, "videos/tempfile.mp4"
 
613
  show_label=False, lines=1, type='password', elem_id="gr-component")
614
 
615
  with gr.Row():
616
+ with gr.Column(scale=1, min_width=TALKING_HEAD_WIDTH, visible=True):
617
+ speak_text_cb = gr.Checkbox(label="Enable speech", value=False)
618
+ speak_text_cb.change(update_foo, inputs=[speak_text_cb, speak_text_state],
619
+ outputs=[speak_text_state])
620
+
621
+ my_file = gr.File(label="Upload a file", type="file", visible=False)
622
+ tmp_file = gr.File(LOOPING_TALKING_HEAD, visible=False)
623
+ # tmp_file_url = "/file=" + tmp_file.value['name']
624
+ htm_video = create_html_video(LOOPING_TALKING_HEAD, TALKING_HEAD_WIDTH)
625
+ video_html = gr.HTML(htm_video)
626
+
627
+ # my_aud_file = gr.File(label="Audio file", type="file", visible=True)
628
+ tmp_aud_file = gr.File("audios/tempfile.mp3", visible=False)
629
+ tmp_aud_file_url = "/file=" + tmp_aud_file.value['name']
630
+ htm_audio = f'<audio><source src={tmp_aud_file_url} type="audio/mp3"></audio>'
631
+ audio_html = gr.HTML(htm_audio)
632
+
633
  with gr.Column(scale=7):
634
  chatbot = gr.Chatbot(elem_id="gr-component")
635
 
 
651
  trace_chain_cb.change(update_foo, inputs=[trace_chain_cb, trace_chain_state],
652
  outputs=[trace_chain_state])
653
 
654
+ speak_text_cb = gr.Checkbox(label="Speak text from agent", value=False)
655
+ speak_text_cb.change(update_foo, inputs=[speak_text_cb, speak_text_state],
656
+ outputs=[speak_text_state])
657
 
658
+ talking_head_cb = gr.Checkbox(label="Show talking head", value=True)
659
+ talking_head_cb.change(update_talking_head, inputs=[talking_head_cb, talking_head_state],
660
+ outputs=[talking_head_state, video_html])
661
 
662
  # monologue_cb = gr.Checkbox(label="Babel fish mode (translate/restate what you enter, no conversational agent)",
663
  # value=False)
 
674
  surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
675
  lang_level_state, translate_to_state, literary_style_state,
676
  qa_chain_state, docsearch_state, use_embeddings_state],
677
+ outputs=[chatbot, history_state, video_html, my_file, audio_html, tmp_aud_file, message])
678
+ # outputs=[chatbot, history_state, message])
679
  # outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
680
 
681
  submit.click(chat, inputs=[openai_api_key_textbox, message, history_state, chain_state, trace_chain_state,
 
685
  surprise_level_state, sadness_level_state, disgust_level_state, anger_level_state,
686
  lang_level_state, translate_to_state, literary_style_state,
687
  qa_chain_state, docsearch_state, use_embeddings_state],
688
+ outputs=[chatbot, history_state, video_html, my_file, audio_html, tmp_aud_file, message])
689
+ # outputs=[chatbot, history_state, message])
690
  # outputs=[chatbot, history_state, audio_html, tmp_aud_file, message])
691
 
692
  openai_api_key_textbox.change(set_openai_api_key,