-
Notifications
You must be signed in to change notification settings - Fork 26
/
app.py
190 lines (166 loc) · 9.81 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import os
import gradio as gr
import ocr
import time
from cover import cover
from video import VideoProcessor
from tts import audio_process
import constant
import video_merge
import novel_tools
import paddle_ocr
import video_effect_text
import video_effect_video
def video_process(inp1=None, inp2=None, inp3=None, inp4=None, inp6=None, inp7=None, inp8=None, inp9=None, inp14=None):
repair = False
if len(inp9) > 0:
repair = True
corp = False
if len(inp14) > 0:
corp = True
video_processor = VideoProcessor(text=inp1, voice=inp2, image_file=inp6, size=inp7, transform=inp8, rate=inp3,
volume=inp4, repair=repair, corp=corp)
file_path = video_processor.text_image_to_video()
return file_path
def batch_process(inp2=None, inp3=None, inp4=None, inp7=None, inp8=None, inp9=None, inp10=None, inp11=None, inp12=None,
inp13=None, inp14=None, inp15=None, inp16=None ,inp20=None,inp21=None,inp22=None,inp23=None):
if inp20 != None:
cover(inp21, inp22, inp23 , inp20)
with open(inp10, 'r') as text_file:
lines = text_file.readlines()
image_extensions = constant.image_extensions
image_files = [file for file in os.listdir(inp11) if file.endswith(image_extensions)]
image_files = sorted(image_files, key=novel_tools.extract_number)
for line, image_file in zip(lines, image_files):
line = line.strip()
image_file_path = os.path.join(inp11, image_file)
video_process(line, inp2, inp3, inp4, image_file_path, inp7, inp8, inp9, inp14)
time.sleep(len(image_files))
if inp15 in constant.size_mapping:
width, height = constant.size_mapping[inp15]
else:
width, height = 1920, 1080
if inp16 == "word":
video_effect_text.text_effect(screensize=(width, height), text=inp15)
elif inp16 == "video":
video_effect_video.image_effect(screensize=(width, height), text=inp15)
return video_merge.merge_video(inp12, inp13)
def merge_process(inp12=None, inp13=None):
if inp12 == None and inp13 == None:
return
return video_merge.merge_video(inp12, inp13)
with gr.Blocks(theme='freddyaboulton/dracula_revamped') as demo:
gr.Markdown(f"### [NovelT](https://github.com/douhaohaode/NovelT)")
with gr.Tab(constant.ocr_title):
with gr.Tab(constant.paddleocr_title):
with gr.Row():
inp_pil = gr.Image(type="pil", label=constant.image_title)
out_video_text = gr.Textbox(label=constant.ocr_subtitle, interactive=True)
btn1 = gr.Button(constant.oct_btn_title)
btn1.click(fn=paddle_ocr.red_image, inputs=[inp_pil], outputs=out_video_text)
with gr.Row():
inp_video = gr.Video(label=constant.video_title, type="filepath")
out_video = gr.Textbox(label=constant.ocr_subtitle, max_lines=9999, interactive=True)
btn_video = gr.Button(constant.oct_btn_title)
btn_video.click(fn=paddle_ocr.red_voide, inputs=[inp_video], outputs=out_video)
with gr.Row():
inp = gr.Textbox(placeholder=constant.path_title, label=constant.path_title)
out = gr.Textbox(label=constant.ocr_subtitle, max_lines=9999, interactive=True)
btn = gr.Button(constant.oct_btn_title)
btn.click(fn=paddle_ocr.red_path, inputs=[inp], outputs=out)
with gr.Tab(constant.pytesseract_title):
with gr.Row():
ocr_lan = gr.Radio(constant.ocrNameArray, label="识别语言", value=constant.ocrNameArray[0])
with gr.Row():
inp_pil = gr.Image(type="pil", label=constant.image_title)
out_video_text = gr.Textbox(label=constant.ocr_subtitle, interactive=True)
btn1 = gr.Button(constant.oct_btn_title)
btn1.click(fn=ocr.red_image, inputs=[inp_pil, ocr_lan], outputs=out_video_text)
with gr.Row():
inp = gr.Textbox(placeholder=constant.path_title, label=constant.path_title)
out = gr.Textbox(label=constant.ocr_subtitle, max_lines=9999, interactive=True)
btn = gr.Button(constant.oct_btn_title)
btn.click(fn=ocr.red_path, inputs=[inp, ocr_lan], outputs=out)
with gr.Tab(constant.tts_title):
with gr.Row():
inp1 = gr.Textbox(placeholder=constant.title_placeholder, label=constant.text_title)
inp2 = gr.Radio(constant.voiceArray, label=constant.anchor_title)
with gr.Column():
inp3 = gr.Slider(-50.0, 50.0, value=0.0, label=constant.voice_title, info=constant.voice_desc)
inp4 = gr.Slider(-50.0, 50.0, value=0.0, label=constant.volume_title, info=constant.volume_desc)
inp5 = gr.Textbox(placeholder=constant.file_placeholder_title, label=constant.file_title)
out = gr.Audio(label=constant.audio_title, type="filepath")
btn = gr.Button(constant.generate_title)
btn.click(fn=audio_process, inputs=[inp1, inp2, inp3, inp4, inp5], outputs=out)
live = True
with gr.Tab(constant.video_title):
with gr.Row():
inp1 = gr.Textbox(placeholder=constant.title_placeholder, label=constant.text_title,
value=constant.welcome_title)
with gr.Column():
inp6 = gr.Textbox(placeholder=constant.path_subtitle, label=constant.image_path_title,
value='./source/image/1.jpg')
inp7 = gr.Radio(constant.sizeArray, label=constant.size_title, value=constant.sizeArray[0])
inp8 = gr.Radio(constant.transform_list, label=constant.transform_title,
value=constant.transform_list[0])
with gr.Row():
inp9 = gr.CheckboxGroup([constant.repair_title], label=constant.cartoon_title)
inp14 = gr.CheckboxGroup([constant.corp_title], label=constant.video_corp_title)
with gr.Row():
with gr.Column():
inp2 = gr.Radio(constant.voiceArray, label=constant.anchor_title, value=constant.voiceArray[0])
inp3 = gr.Slider(-50.0, 50.0, value=0.0, label=constant.voice_title, info=constant.voice_desc)
inp4 = gr.Slider(-50.0, 50.0, value=0.0, label=constant.volume_title, info=constant.volume_desc)
video_file_path = gr.Video(label=constant.video_title, type="filepath")
with gr.Row():
video_btn = gr.Button(constant.generate_title)
video_btn.click(fn=video_process, inputs=[inp1, inp2, inp3, inp4, inp6, inp7, inp8, inp9, inp14],
outputs=video_file_path)
with gr.Tab(constant.batch_title):
with gr.Row():
inp10 = gr.Textbox(placeholder=constant.path_subtitle, label=constant.text_path_title,
value='./source/image/1.txt')
inp11 = gr.Textbox(placeholder=constant.path_subtitle, label=constant.image_file_path_title,
value='./source/image/')
with gr.Row():
with gr.Row():
inp2 = gr.Radio(constant.voiceArray, label=constant.anchor_title, value=constant.voiceArray[3])
with gr.Column():
inp3 = gr.Slider(-50.0, 50.0, value=23.0, label=constant.voice_title, info=constant.voice_desc)
inp4 = gr.Slider(-50.0, 50.0, value=40.0, label=constant.volume_title, info=constant.volume_desc)
with gr.Row():
with gr.Row():
inp7 = gr.Radio(constant.sizeArray, label=constant.size_title, value=constant.sizeArray[0])
inp8 = gr.Radio(constant.transform_list, label=constant.transform_title,
value=constant.transform_list[1])
with gr.Row():
with gr.Row():
inp9 = gr.CheckboxGroup([constant.repair_title], label=constant.cartoon_title)
inp14 = gr.CheckboxGroup([constant.corp_title], label=constant.video_corp_title)
with gr.Column():
inp15 = gr.Textbox(placeholder=constant.title_placeholder, label=constant.sequence_title,
value=constant.welcome_title)
inp16 = gr.Radio(constant.title_sequence_list, label=constant.sequence_label,
value=constant.title_sequence_list[0])
with gr.Row():
with gr.Column():
inp12 = gr.Textbox(placeholder=constant.path_subtitle, label=constant.video_merge_file_title,
value='./source/video/')
inp13 = gr.Radio(constant.merge_array, label=constant.background_audio_title,
value=constant.merge_array[6])
merge__video_out = gr.Video(label=constant.video_title, type="filepath")
with gr.Row():
inp20 = gr.Textbox(placeholder=constant.path_subtitle, label="封面图路径",
value='')
inp21 = gr.Textbox(label="标题1", value='打造最强宗门')
inp22 = gr.Textbox(label="标题1", value='第一集')
inp23 = gr.Textbox(label="标题1", value='弟子数十万 个个是妖孽')
batch_video_btn = gr.Button(constant.generate_title)
# batch_out = gr.Textbox(label=constant.progress_title)
batch_video_btn.click(fn=batch_process,
inputs=[inp2, inp3, inp4, inp7, inp8, inp9, inp10, inp11, inp12, inp13, inp14, inp15,
inp16, inp20, inp21, inp22, inp23],
outputs=merge__video_out)
# merge__video_btn = gr.Button(constant.generate_title)
# merge__video_btn.click(fn=merge_process, inputs=[inp12, inp13], outputs=merge__video_out)
demo.launch()