Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
)
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# generate_video.py
|
2 |
+
|
3 |
+
from gtts import gTTS
|
4 |
+
from pydub import AudioSegment
|
5 |
+
import cv2
|
6 |
import gradio as gr
|
7 |
|
8 |
+
def text_to_wav(text, file_name):
|
9 |
+
language = 'en'
|
10 |
+
tts = gTTS(text=text, lang=language, slow=False)
|
11 |
+
tts.save(file_name)
|
12 |
+
|
13 |
+
def generate_video(input_image, input_text):
|
14 |
+
text_file = "input_audio.wav"
|
15 |
+
video_file = "/path/to/generated_video.mp4"
|
16 |
+
|
17 |
+
text_to_wav(input_text, text_file)
|
18 |
+
|
19 |
+
audio = AudioSegment.from_file(text_file)
|
20 |
+
duration_seconds = len(audio) / 1000.0
|
21 |
+
|
22 |
+
img = cv2.imread(input_image)
|
23 |
+
|
24 |
+
fps = 60
|
25 |
+
video_duration_seconds = round(duration_seconds) * 3
|
26 |
+
|
27 |
+
video = cv2.VideoWriter(video_file, cv2.VideoWriter_fourcc(*'mp4v'), fps, (img.shape[1], img.shape[0]))
|
28 |
+
|
29 |
+
for _ in range(int(fps * video_duration_seconds)):
|
30 |
+
video.write(img)
|
31 |
+
|
32 |
+
video.release()
|
33 |
+
|
34 |
+
return video_file
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
iface = gr.Interface(
|
38 |
+
fn=generate_video,
|
39 |
+
inputs=["image", "text"],
|
40 |
+
outputs="video",
|
41 |
+
)
|
42 |
+
|
43 |
+
iface.launch(share=True)
|