Dy commited on
Commit
01b92a0
1 Parent(s): a8e9526

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -4
app.py CHANGED
@@ -1,3 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import openai
2
  import requests
3
  import os
@@ -11,9 +63,7 @@ import tempfile
11
  import numpy as np
12
  import gradio as gr
13
 
14
- OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
15
- ELEVEN_LABS_API = os.environ['ELEVEN_LABS_API']
16
- PASSWORD_AUTH = os.environ['PASSWORD_AUTH']
17
 
18
  # Set your OpenAI API key here
19
  openai.api_key = OPENAI_API_KEY
@@ -346,7 +396,11 @@ with gr.Blocks() as demo:
346
  prompt_user = gr.Textbox(label="Enter your prompt")
347
  prompt_input = gr.Dropdown(['how-to', 'documentary', 'sports-commentator', 'custom-prompt'], label="Choose Your Narration")
348
  voice_type = gr.Dropdown(['masculine-american', 'masculine-british', 'feminine-american', 'feminine-british'], label="Choose Your Voice")
 
349
  generate_btn = gr.Button(value="Generate")
 
 
 
350
  #render_btn = gr.Button(value="Render")
351
  #print_btn = gr.Button(value="Print")
352
  with gr.Column():
@@ -354,12 +408,13 @@ with gr.Blocks() as demo:
354
  output_file = gr.Video(label="Ouput video file.")
355
  output_voiceover = gr.Textbox(label="Generated Text")
356
  regenerate_btn = gr.Button(value="Re-generate")
 
357
  #print_text = gr.Text(label="Printing")
358
 
359
 
360
  generate_btn.click(process_video, inputs=[video_input, prompt_user, prompt_input, voice_type], outputs=[output_file,output_voiceover])
361
  regenerate_btn.click(regenerate, inputs=[video_input, output_voiceover, voice_type], outputs=[output_file,output_voiceover])
362
-
363
 
364
 
365
  demo.launch(auth=("admin", PASSWORD_AUTH))
 
1
+ import os
2
+ OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
3
+ ELEVEN_LABS_API = os.environ['ELEVEN_LABS_API']
4
+ PASSWORD_AUTH = os.environ['PASSWORD_AUTH']
5
+
6
+ from elevenlabs import clone, generate, play, save
7
+ from elevenlabs import set_api_key
8
+ set_api_key(ELEVEN_LABS_API)
9
+
10
+ def process_video_custom_voice(uploaded_file, prompt_user, prompt_input, custom_audio, voice_prompt):
11
+
12
+ if type(uploaded_file) == str:
13
+ video_filename = uploaded_file
14
+ else:
15
+ video_filename = uploaded_file.name
16
+ print("video", video_filename)
17
+
18
+ base64Frames, video_filename, video_duration = video_to_frames(video_filename)
19
+
20
+ final_prompt = prompt_type(prompt_user, prompt_input, video_duration)
21
+ print(final_prompt)
22
+ text = frames_to_story(base64Frames, final_prompt, video_duration)
23
+
24
+ if type(custom_audio) == str:
25
+ custom_audio_filename = custom_audio
26
+ else:
27
+ custom_audio_filename = custom_audio.name
28
+ print("custom audio", custom_audio_filename)
29
+
30
+ voice = clone(
31
+ name="Custom Voice",
32
+ description=f"{voice_prompt}", # Optional
33
+ files=[custom_audio_filename],
34
+ )
35
+
36
+ audio = generate(text=text, voice=voice)
37
+ save(audio, custom_audio_filename)
38
+
39
+ audio_filename = custom_audio_filename
40
+
41
+ # Merge audio and video
42
+ output_video_filename = os.path.splitext(video_filename)[0] + '_output.mp4'
43
+ final_video_filename = merge_audio_video(video_filename, audio_filename, output_video_filename)
44
+ print("final", final_video_filename)
45
+
46
+ if type(uploaded_file) != str:
47
+ os.unlink(video_filename)
48
+ os.unlink(audio_filename)
49
+
50
+ return final_video_filename, text
51
+
52
+
53
  import openai
54
  import requests
55
  import os
 
63
  import numpy as np
64
  import gradio as gr
65
 
66
+
 
 
67
 
68
  # Set your OpenAI API key here
69
  openai.api_key = OPENAI_API_KEY
 
396
  prompt_user = gr.Textbox(label="Enter your prompt")
397
  prompt_input = gr.Dropdown(['how-to', 'documentary', 'sports-commentator', 'custom-prompt'], label="Choose Your Narration")
398
  voice_type = gr.Dropdown(['masculine-american', 'masculine-british', 'feminine-american', 'feminine-british'], label="Choose Your Voice")
399
+
400
  generate_btn = gr.Button(value="Generate")
401
+ voice_sample = gr.File(label="Use custom made voice.")
402
+ voice_prompt = gr.Textbox(label="Enter voice prompt.")
403
+
404
  #render_btn = gr.Button(value="Render")
405
  #print_btn = gr.Button(value="Print")
406
  with gr.Column():
 
408
  output_file = gr.Video(label="Ouput video file.")
409
  output_voiceover = gr.Textbox(label="Generated Text")
410
  regenerate_btn = gr.Button(value="Re-generate")
411
+ custom_voice_btn = gr.Button(value="Use Custom Voice")
412
  #print_text = gr.Text(label="Printing")
413
 
414
 
415
  generate_btn.click(process_video, inputs=[video_input, prompt_user, prompt_input, voice_type], outputs=[output_file,output_voiceover])
416
  regenerate_btn.click(regenerate, inputs=[video_input, output_voiceover, voice_type], outputs=[output_file,output_voiceover])
417
+ custom_voice_btn.click(process_video_custom_voice, inputs=[video_input, prompt_user, prompt_input, voice_sample, voice_prompt], outputs=[output_file,output_voiceover])
418
 
419
 
420
  demo.launch(auth=("admin", PASSWORD_AUTH))