digidau commited on
Commit
7f420a2
·
verified ·
1 Parent(s): 836e38d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -0
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import shutil
4
+
5
+ from converter import convert_qurancaption_to_qvm
6
+ from background import generate_background
7
+ from subtitle import generate_ass
8
+ from renderer import render_final_video
9
+
10
+
11
+ os.makedirs('uploads', exist_ok=True)
12
+ os.makedirs('temp', exist_ok=True)
13
+ os.makedirs('outputs', exist_ok=True)
14
+
15
+
16
+ def process(images, audio, timing_json):
17
+
18
+ for folder in ['uploads', 'temp']:
19
+ if os.path.exists(folder):
20
+ shutil.rmtree(folder)
21
+ os.makedirs(folder)
22
+
23
+ image_paths = []
24
+
25
+ for i, img in enumerate(images):
26
+ ext = os.path.splitext(img.name)[1]
27
+ dst = f'uploads/{i:03d}{ext}'
28
+ shutil.copy(img.name, dst)
29
+ image_paths.append(dst)
30
+
31
+ audio_path = 'uploads/audio.mp3'
32
+ shutil.copy(audio, audio_path)
33
+
34
+ json_path = 'uploads/timing.json'
35
+ shutil.copy(timing_json.name, json_path)
36
+
37
+ qvm_json = 'temp/qvm_timing.json'
38
+
39
+ convert_qurancaption_to_qvm(
40
+ json_path,
41
+ qvm_json
42
+ )
43
+
44
+ background_path = 'temp/background.mp4'
45
+
46
+ generate_background(
47
+ image_paths,
48
+ background_path
49
+ )
50
+
51
+ subtitle_path = 'temp/subtitles.ass'
52
+
53
+ generate_ass(
54
+ qvm_json,
55
+ subtitle_path
56
+ )
57
+
58
+ final_video = 'outputs/final.mp4'
59
+
60
+ render_final_video(
61
+ background_path,
62
+ audio_path,
63
+ subtitle_path,
64
+ final_video
65
+ )
66
+
67
+ return final_video
68
+
69
+
70
+ with gr.Blocks() as demo:
71
+
72
+ gr.Markdown('# Quran Cinematic Video Generator')
73
+
74
+ images = gr.Files(
75
+ label='Upload Images',
76
+ file_count='multiple'
77
+ )
78
+
79
+ audio = gr.Audio(
80
+ type='filepath',
81
+ label='Upload Audio'
82
+ )
83
+
84
+ timing_json = gr.File(
85
+ label='Upload QuranCaption JSON'
86
+ )
87
+
88
+ btn = gr.Button('Generate Video')
89
+
90
+ output = gr.Video()
91
+
92
+ btn.click(
93
+ process,
94
+ inputs=[images, audio, timing_json],
95
+ outputs=output
96
+ )
97
+
98
+ from setup import setup_qvm
99
+ setup_qvm()
100
+
101
+ demo.launch()