JLW commited on
Commit
3eb5f7d
·
1 Parent(s): 04bbd8e

Begin implementing video

Browse files
Files changed (2) hide show
  1. app.py +10 -13
  2. videos/tempfile.mp4 +2 -2
app.py CHANGED
@@ -31,14 +31,17 @@ def chat(inp, history, agent):
31
  history = history or []
32
  output = agent.run(inp)
33
  history.append((inp, output))
34
- return history, history
35
 
 
36
 
37
- def do_html_video_speak(testing):
 
 
 
38
  headers = {"Authorization": f"Bearer {os.environ['EXHUMAN_API_KEY']}"}
39
  body = {
40
  'bot_name': 'Masahiro',
41
- 'bot_response': 'This is a test. This is a test. This is a test. This is a test. This is a test',
42
  'voice_name': 'Masahiro-EN'
43
  }
44
  api_endpoint = "https://api.exh.ai/animations/v1/generate_lipsync"
@@ -51,7 +54,7 @@ def do_html_video_speak(testing):
51
  f.write(response_stream.read())
52
  temp_file = gr.File("videos/tempfile.mp4")
53
  temp_file_url = "/file=" + temp_file.value['name']
54
- html_video = f'<video width="256" height="256" autoplay><source src={temp_file_url} type="video/mp4"></video>'
55
  else:
56
  print('video url unknown')
57
  return html_video, "videos/tempfile.mp4"
@@ -68,13 +71,7 @@ with block:
68
  htm_video = f'<video width="256" height="256" autoplay muted loop><source src={tmp_file_url} type="video/mp4" poster="Masahiro.png"></video>'
69
  video_html = gr.HTML(htm_video)
70
 
71
- # video_html = gr.HTML("f'<video width=\"512\" height=\"512\" autoplay><source src={tmp_file_url} type=\"video/mp4\"></video>")
72
-
73
- # video_html = gr.HTML("""<video width="100%" height="100%" controls autoplay loop>
74
- # <source src="videos/Masahiro.mp4"
75
- # type="video/mp4"></video>""")
76
-
77
- gr.Markdown("<h3><center>LangChain AI</center></h3>")
78
 
79
  openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
80
  show_label=False, lines=1, type='password')
@@ -110,8 +107,8 @@ with block:
110
  state = gr.State()
111
  agent_state = gr.State()
112
 
113
- submit.click(chat, inputs=[message, state, agent_state], outputs=[chatbot, state])
114
- message.submit(chat, inputs=[message, state, agent_state], outputs=[chatbot, state])
115
  test.click(do_html_video_speak, inputs=[message], outputs=[video_html, my_file])
116
 
117
  openai_api_key_textbox.change(set_openai_api_key,
 
31
  history = history or []
32
  output = agent.run(inp)
33
  history.append((inp, output))
 
34
 
35
+ html_video, temp_file = do_html_video_speak(output)
36
 
37
+ return history, history, html_video, temp_file
38
+
39
+
40
+ def do_html_video_speak(words_to_speak):
41
  headers = {"Authorization": f"Bearer {os.environ['EXHUMAN_API_KEY']}"}
42
  body = {
43
  'bot_name': 'Masahiro',
44
+ 'bot_response': words_to_speak,
45
  'voice_name': 'Masahiro-EN'
46
  }
47
  api_endpoint = "https://api.exh.ai/animations/v1/generate_lipsync"
 
54
  f.write(response_stream.read())
55
  temp_file = gr.File("videos/tempfile.mp4")
56
  temp_file_url = "/file=" + temp_file.value['name']
57
+ html_video = f'<video width="256" height="256" autoplay><source src={temp_file_url} type="video/mp4" poster="Masahiro.png"></video>'
58
  else:
59
  print('video url unknown')
60
  return html_video, "videos/tempfile.mp4"
 
71
  htm_video = f'<video width="256" height="256" autoplay muted loop><source src={tmp_file_url} type="video/mp4" poster="Masahiro.png"></video>'
72
  video_html = gr.HTML(htm_video)
73
 
74
+ gr.Markdown("<h3><center>Q&A GPT3.5/LangChain</center></h3>")
 
 
 
 
 
 
75
 
76
  openai_api_key_textbox = gr.Textbox(placeholder="Paste your OpenAI API key (sk-...)",
77
  show_label=False, lines=1, type='password')
 
107
  state = gr.State()
108
  agent_state = gr.State()
109
 
110
+ submit.click(chat, inputs=[message, state, agent_state], outputs=[chatbot, state, video_html, my_file])
111
+ message.submit(chat, inputs=[message, state, agent_state], outputs=[chatbot, state, video_html, my_file])
112
  test.click(do_html_video_speak, inputs=[message], outputs=[video_html, my_file])
113
 
114
  openai_api_key_textbox.change(set_openai_api_key,
videos/tempfile.mp4 CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d0f885d4dc3c110dac03d45fa8acecaff0c1071c3d01db22c24dc683aaf4a9a5
3
- size 210630
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a93c78fe93fcb2f465949ccff2f78eb90099cd0c311acd65a7a81112a41d2c08
3
+ size 256467