Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,12 +9,9 @@ from gen_client import *
|
|
9 |
myHumanGen = HumanGenService()
|
10 |
oss_service = ossService()
|
11 |
|
12 |
-
|
13 |
-
ENABLE_OSS_RESOURCES = True
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
result_video_oss_url = {} # user_id, (list[signed_url), list[oss_path])]
|
18 |
|
19 |
def tab_func_template():
|
20 |
prompt = ""
|
@@ -23,8 +20,8 @@ def tab_func_prompt():
|
|
23 |
ref_video_path = None
|
24 |
return ref_video_path, 'prompt_mode'
|
25 |
|
26 |
-
with open('script.txt', encoding="utf-8") as f:
|
27 |
-
|
28 |
|
29 |
# def dataset_func(evt: gr.SelectData):
|
30 |
# ref_video_path = evt.value[0]
|
@@ -50,15 +47,15 @@ def video_2_prompt_func(ref_video_path):
|
|
50 |
def get_user_result_video_list(uuid, date_string, num):
|
51 |
directory='video_generation/Service/'+date_string+'/'+uuid+'/'
|
52 |
for obj in oss2.ObjectIterator(oss_service.bucket, prefix=directory, delimiter='/'):
|
53 |
-
print(f"
|
54 |
break
|
55 |
else:
|
56 |
-
print(f"
|
57 |
return [],[]
|
58 |
no_check_video_list = []
|
59 |
no_check_timer_list = []
|
60 |
for obj in oss2.ObjectIterator(oss_service.bucket, prefix=directory, delimiter = '/'):
|
61 |
-
if obj.is_prefix(): #
|
62 |
file_full_path = obj.key+'result.mp4'
|
63 |
exist = oss_service.bucket.object_exists(file_full_path)
|
64 |
|
@@ -68,7 +65,7 @@ def get_user_result_video_list(uuid, date_string, num):
|
|
68 |
print(f'tmp_directory = {tmp_directory}')
|
69 |
for obj_xxx in oss2.ObjectIterator(oss_service.bucket, prefix=tmp_directory, delimiter = '/'):
|
70 |
print(f'obj_xxx.key = {obj_xxx.key}')
|
71 |
-
if obj_xxx.is_prefix(): #
|
72 |
pass
|
73 |
else:
|
74 |
import re
|
@@ -91,39 +88,38 @@ def get_user_result_video_list(uuid, date_string, num):
|
|
91 |
mb_num = float(bytes_num) / (1000 ** 2) # MB
|
92 |
# print(f"Object Size: {mb_num} MB")
|
93 |
|
94 |
-
if mb_num > 0.1: #
|
95 |
last_modified = object_meta.headers.get('Last-Modified')
|
96 |
# print(f"Last Modified: {last_modified}")
|
97 |
from email.utils import parsedate_to_datetime
|
98 |
-
#
|
99 |
last_modified_datetime = parsedate_to_datetime(last_modified)
|
100 |
-
#
|
101 |
last_modified_timestamp = int(last_modified_datetime.timestamp())
|
102 |
-
|
103 |
-
|
104 |
no_check_video_list.append(file_full_path)
|
105 |
no_check_timer_list.append(last_modified_timestamp)
|
106 |
else:
|
107 |
-
print(f'
|
108 |
-
else:
|
109 |
-
print(f'
|
110 |
-
# last_modified = obj.last_modified #
|
111 |
-
# print(f"File: {obj.key}, Last Modified: {last_modified}")
|
112 |
|
113 |
valid_video_list = []
|
114 |
valid_image_list = []
|
115 |
if len(no_check_video_list) > 0:
|
116 |
if len(no_check_video_list) > 1:
|
117 |
# sort by time
|
118 |
-
zipped_lists = zip(no_check_timer_list, no_check_video_list)
|
119 |
-
|
|
|
120 |
list1_sorted, list2_sorted = zip(*sorted_pairs)
|
121 |
no_check_timer_list = list(list1_sorted)
|
122 |
no_check_video_list = list(list2_sorted)
|
123 |
|
124 |
for file_full_path in no_check_video_list:
|
125 |
oss_video_path = "oss://vigen-invi/" + file_full_path
|
126 |
-
print(f'
|
127 |
_, video_url = oss_service.sign(oss_video_path, timeout=3600*100)
|
128 |
valid_video_list.append(video_url)
|
129 |
style = "video/snapshot,t_1000,f_jpg,w_544,h_768,m_fast"
|
@@ -146,14 +142,8 @@ def refresh_video(uuid, request_id):
|
|
146 |
new_image_list = []
|
147 |
if process_status == 'runing':
|
148 |
print(f'process_status: {process_status}')
|
149 |
-
#
|
150 |
-
#
|
151 |
-
# new_list.append(video_url)
|
152 |
-
# img_oss_path = "oss://vigen-invi/video_generation/logo/runing.png"
|
153 |
-
# _, img_url = oss_service.sign(img_oss_path, timeout=3600*100)
|
154 |
-
# new_image_list.append(img_url)
|
155 |
-
new_list.append(None)
|
156 |
-
new_image_list.append(None)
|
157 |
date_string = datetime.datetime.now().strftime('%Y-%m-%d')
|
158 |
valid_video_list, valid_image_list = get_user_result_video_list(uuid, date_string, 3)
|
159 |
new_list = new_list + valid_video_list
|
@@ -192,9 +182,9 @@ def refresh_video(uuid, request_id):
|
|
192 |
new_list.append(None)
|
193 |
new_image_list.append(None)
|
194 |
|
195 |
-
return notes, new_list[0], new_list[1], new_list[2], new_list[3]
|
196 |
|
197 |
-
with gr.Blocks(title = "
|
198 |
css='style.css',
|
199 |
theme=gr.themes.Soft(
|
200 |
radius_size=gr.themes.sizes.radius_sm,
|
@@ -203,18 +193,11 @@ with gr.Blocks(title = "追影",
|
|
203 |
) as demo:
|
204 |
with gr.Row():
|
205 |
gr.HTML(f"""
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
margin-left: 0px !important;
|
210 |
-
"
|
211 |
-
>
|
212 |
-
<img id='logo_img' src='{RESOURCES.logo_img0}' >
|
213 |
-
</div>
|
214 |
-
</br>
|
215 |
""")
|
216 |
|
217 |
-
template_videos_to_ref = examples['template_video']
|
218 |
if ENABLE_OSS_RESOURCES:
|
219 |
template_videos_to_ref = []
|
220 |
template_video_list = examples['template_video']
|
@@ -223,53 +206,63 @@ with gr.Blocks(title = "追影",
|
|
223 |
oss_path = "oss://vigen-invi/video_generation/template_video1/" + file_name
|
224 |
_, url = oss_service.sign(oss_path, timeout=3600*100)
|
225 |
template_videos_to_ref.append(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
|
|
|
228 |
gr.Markdown("""
|
229 |
-
- ⭐️ 1
|
230 |
-
- ⭐️ 2
|
231 |
-
- ⭐️ 3
|
232 |
-
- ⭐️ 4
|
233 |
""")
|
234 |
|
235 |
-
input_mode = gr.Text(value="
|
236 |
with gr.Row():
|
237 |
-
with gr.Column(scale=1):
|
238 |
-
# gr.Markdown("输入形象和动作",elem_id='font_style')
|
239 |
with gr.Group(elem_id='show_box'):
|
240 |
-
gr.Markdown("
|
241 |
with gr.Column():
|
242 |
with gr.Group(elem_id='show_box1'):
|
243 |
-
with gr.Row():
|
244 |
-
#左侧图片预览
|
245 |
ref_image = gr.Image(sources='upload', type='filepath', show_label=False, label='输入图片',elem_id='show_window_image')
|
246 |
-
#右侧图片列表
|
247 |
gr.Examples(examples['examples_images'], examples_per_page=9, inputs=[ref_image], label='')
|
248 |
|
249 |
-
with gr.Row():
|
250 |
-
|
251 |
-
model_id = gr.Checkbox(label="卡通视频生成", show_label=False)
|
252 |
|
253 |
-
with gr.Column():
|
254 |
-
gr.Markdown("
|
255 |
-
|
256 |
-
with gr.Tab("文生视频") as tab1:
|
257 |
-
# prompt = gr.Textbox(label="Prompt提示词", show_label=False, text_align='left')
|
258 |
-
example_prompts= []
|
259 |
-
file = open(ref_video_prompt, 'r')
|
260 |
-
for line in file.readlines():
|
261 |
-
example_prompts.append(line)
|
262 |
-
file.close()
|
263 |
-
prompt = gr.Dropdown(label="Prompt提示词",choices=example_prompts, show_label=False, allow_custom_value=True)
|
264 |
|
265 |
-
with gr.Tab("
|
266 |
-
prompt_template = gr.Textbox(placeholder="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
with gr.Row():
|
268 |
-
# FIXME: the width/height setting not work here,
|
269 |
-
ref_video = gr.Video(sources='upload', show_label=False, label='
|
270 |
-
# gr.Examples(examples['template_video'], examples_per_page=9,inputs=[ref_video], label='
|
271 |
# dataset_select = gr.Dataset(
|
272 |
-
# label='
|
273 |
# components=[gr.Video(visible=False)],
|
274 |
# samples=examples['template_video'],
|
275 |
# samples_per_page=9,
|
@@ -279,7 +272,7 @@ with gr.Blocks(title = "追影",
|
|
279 |
# # elem_id='template_param',
|
280 |
# )
|
281 |
gr.Examples(
|
282 |
-
label='
|
283 |
examples=template_videos_to_ref,
|
284 |
inputs=ref_video,
|
285 |
outputs=[ref_video, prompt_template],
|
@@ -287,64 +280,62 @@ with gr.Blocks(title = "追影",
|
|
287 |
examples_per_page=9,
|
288 |
cache_examples=True, #run_on_click=True,
|
289 |
)
|
290 |
-
# prompt_template = gr.Textbox(label="Prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
|
292 |
-
with gr.Row():
|
293 |
-
#
|
294 |
-
run_button = gr.Button(value="
|
295 |
-
# btn = gr.Button("
|
296 |
|
297 |
-
with gr.Column(scale=1):
|
298 |
-
# gr.Markdown("
|
299 |
with gr.Group(elem_id='show_box2'):
|
300 |
with gr.Row():
|
301 |
-
with gr.
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
refresh_button = gr.Button(value="刷新", elem_id='button_param1')
|
308 |
|
309 |
with gr.Row():
|
310 |
-
output_video0 = gr.Video(format="mp4", show_label=False, label="Result Video", autoplay=True, elem_id='
|
311 |
-
|
312 |
-
output_video1 = gr.Video(format="mp4", show_label=False, label="Result Video", autoplay=True,elem_id='show_window_result2', elem_classes="show_window_result")
|
313 |
-
output_snapshot_image1 = gr.Image(sources='upload', type='filepath', show_label=False, interactive=False, elem_id='output_snapshot_image2', width=200,height=1, visible=False)
|
314 |
with gr.Row():
|
315 |
-
output_video2 = gr.Video(format="mp4", show_label=False, label="Result Video", autoplay=True,elem_id='
|
316 |
-
|
317 |
-
output_video3 = gr.Video(format="mp4", show_label=False, label="Result Video", autoplay=True,elem_id='show_window_result4', elem_classes="show_window_result")
|
318 |
-
output_snapshot_image3 = gr.Image(sources='upload', type='filepath', show_label=False, interactive=False, elem_id='output_snapshot_image4', width=200,height=1, visible=False)
|
319 |
|
320 |
uuid = gr.Text(label="modelscope_uuid", visible=False)
|
321 |
request_id = gr.Text(label="modelscope_request_id", visible=False)
|
322 |
|
323 |
-
#
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
# gr.Markdown("样例视频",elem_id='font_style')
|
328 |
-
# ref_video1 = gr.Video(sources='upload', height=400, show_label=False, visible=False, label='输入视频',elem_id='show_window_video')
|
329 |
-
# with gr.Group():
|
330 |
-
# gr.Examples(mp4_listss, examples_per_page=12, inputs=[ref_video1], label='')
|
331 |
-
|
332 |
if ENABLE_OSS_RESOURCES:
|
333 |
-
mp4_url_list =
|
334 |
-
for i in range(min(
|
335 |
-
file_name = os.path.basename(
|
336 |
-
# file_name = str(i) + ".mp4"
|
337 |
oss_path = "oss://vigen-invi/video_generation/sample_video/" + file_name
|
338 |
_, video_url = oss_service.sign(oss_path, timeout=3600*100)
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
num_video = 8
|
344 |
if len(mp4_lists) <= num_video:
|
345 |
num_video = len(mp4_lists)
|
346 |
with gr.Row():
|
347 |
-
gr.Markdown("
|
348 |
with gr.Group(elem_id='show_box'):
|
349 |
with gr.Column():
|
350 |
for i in range(int((num_video+num_videos_per_row-1)/num_videos_per_row)):
|
@@ -359,22 +350,29 @@ with gr.Blocks(title = "追影",
|
|
359 |
fn=refresh_video,
|
360 |
queue = False,
|
361 |
inputs=[uuid, request_id],
|
362 |
-
outputs=[user_notes, output_video0, output_video1, output_video2, output_video3
|
363 |
-
output_snapshot_image0, output_snapshot_image1, output_snapshot_image2, output_snapshot_image3 ]
|
364 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
|
366 |
# dataset_select.select(fn=dataset_func, outputs=[ref_video,prompt_template])
|
367 |
|
368 |
# button触发
|
369 |
-
tab0.select(fn=tab_func_template, outputs=[prompt, input_mode]) #
|
370 |
-
tab1.select(fn=tab_func_prompt, outputs=[ref_video, input_mode]) # prompt
|
371 |
|
372 |
def async_process(user_id, request_id, input_mode, ref_image_path, ref_video_path, input_prompt='', prompt_template='',model_id=False):
|
373 |
-
#
|
374 |
check_note_info = myHumanGen.valid_check(user_id, request_id, input_mode, ref_image_path, ref_video_path, input_prompt, prompt_template,model_id)
|
375 |
|
376 |
if check_note_info == '':
|
377 |
-
# 创建独立线程处理
|
378 |
thread = threading.Thread(target=myHumanGen.click_button_func_async, args=(user_id, request_id, input_mode, ref_image_path, ref_video_path, input_prompt, prompt_template,model_id,))
|
379 |
thread.start()
|
380 |
# thread.join()
|
@@ -382,48 +380,33 @@ with gr.Blocks(title = "追影",
|
|
382 |
|
383 |
return refresh_video(user_id, request_id)
|
384 |
else:
|
385 |
-
notes, video_0, video_1, video_2, video_3
|
386 |
-
return check_note_info, video_0, video_1, video_2, video_3
|
387 |
|
388 |
-
|
389 |
-
run_button.click(fn=myHumanGen.click_button_mock_test, inputs=[uuid, request_id, input_mode, ref_image, ref_video, prompt, prompt_template, model_id], outputs=[])
|
390 |
-
else:
|
391 |
-
# run_button.click(fn=myHumanGen.click_button_func_async, inputs=[uuid, request_id, input_mode, ref_image, ref_video, prompt, prompt_template, model_id], outputs=[])
|
392 |
-
run_button.click(fn=async_process, inputs=[uuid, request_id, input_mode, ref_image, ref_video, prompt, prompt_template, model_id], outputs=[user_notes, output_video0, output_video1, output_video2, output_video3,
|
393 |
-
output_snapshot_image0, output_snapshot_image1, output_snapshot_image2, output_snapshot_image3])
|
394 |
-
|
395 |
|
396 |
-
# with gr.Accordion(label="RELEASE_NOTE", elem_id="release_note"):
|
397 |
-
# gr.HighlightedText(label="🔊 MESSAGE", value=[("状态","开发中"),("进度", "55%")], elem_classes='info')
|
398 |
with gr.Row():
|
399 |
-
#
|
400 |
-
# show_label=False,
|
401 |
-
# value=RELEASE_NOTE,
|
402 |
-
# lines=3,
|
403 |
-
# max_lines=3,
|
404 |
-
# interactive=False, scale=2)
|
405 |
-
# 钉钉群二维码信息
|
406 |
gr.HTML(f"""
|
407 |
<div id=css_img_QRCode>
|
408 |
<img id=css_img_QRCode src='{RESOURCES.logo_dingding}'>
|
409 |
</div>
|
410 |
<div id=css_img_QRCode_text>
|
411 |
-
|
412 |
</div>
|
413 |
|
414 |
""")
|
415 |
-
#
|
416 |
gr.HTML(f"""
|
417 |
<div id=css_img_QRCode>
|
418 |
<img id=css_img_QRCode src='{RESOURCES.logo_wechat}'>
|
419 |
</div>
|
420 |
<div id=css_img_QRCode_text>
|
421 |
-
|
422 |
</div>
|
423 |
""")
|
424 |
-
|
425 |
|
426 |
-
#
|
427 |
gr.HTML(f"""
|
428 |
</br>
|
429 |
<div>
|
@@ -431,44 +414,12 @@ with gr.Blocks(title = "追影",
|
|
431 |
</div>
|
432 |
""")
|
433 |
|
434 |
-
|
435 |
-
# snapshots = ""
|
436 |
-
# sample_video_list = get_dirnames(filePath="./data/sample_video", tail=".mp4")
|
437 |
-
# for i in range(12):
|
438 |
-
# if i < len(sample_video_list):
|
439 |
-
# file_name = os.path.basename(sample_video_list[i])
|
440 |
-
# oss_path = "oss://vigen-invi/video_generation/sample_video/" + file_name
|
441 |
-
# style = "video/snapshot,t_1000,f_jpg,w_560,h_800,m_fast"
|
442 |
-
# params = {'x-oss-process': style}
|
443 |
-
# _, url = oss_service.sign(oss_path, timeout=3600*100, params=params)
|
444 |
-
# snapshots = snapshots + url + ";"
|
445 |
-
|
446 |
-
# referenceVideoSnapshots = ""
|
447 |
-
# template_video_list = examples['template_video']
|
448 |
-
# for i in range(9):
|
449 |
-
# if i < len(template_video_list):
|
450 |
-
# file_name = template_video_list[i]
|
451 |
-
# oss_path = "oss://vigen-invi/video_generation/template_video1/" + file_name
|
452 |
-
# style = "video/snapshot,t_1000,f_jpg,w_56,h_80,m_fast" #112,160
|
453 |
-
# params = {'x-oss-process': style}
|
454 |
-
# _, url = oss_service.sign(oss_path, timeout=3600*100, params=params)
|
455 |
-
# referenceVideoSnapshots = referenceVideoSnapshots + url + ";"
|
456 |
-
# format_text = script_text_to_load_results.format(snapshots, referenceVideoSnapshots)
|
457 |
-
# demo.load(_js = format_text)
|
458 |
-
|
459 |
-
# concurrency_count concurrency_limit max_threads
|
460 |
demo.queue(api_open=False, max_size=1000).launch(
|
461 |
-
server_name="0.0.0.0",
|
462 |
-
share=
|
463 |
server_port=7860,
|
464 |
root_path=f"/{os.getenv('GRADIO_PROXY_PATH')}" if os.getenv('GRADIO_PROXY_PATH') else ""
|
465 |
)
|
466 |
|
467 |
-
# demo.launch(
|
468 |
-
# server_name="0.0.0.0" if os.getenv('GRADIO_LISTEN', '') != '' else "127.0.0.1",
|
469 |
-
# share=False,
|
470 |
-
# enable_queue=True,
|
471 |
-
# root_path=f"/{os.getenv('GRADIO_PROXY_PATH')}" if os.getenv('GRADIO_PROXY_PATH') else ""
|
472 |
-
# )
|
473 |
-
|
474 |
|
|
|
9 |
myHumanGen = HumanGenService()
|
10 |
oss_service = ossService()
|
11 |
|
12 |
+
ENABLE_OSS_RESOURCES = False
|
|
|
13 |
|
14 |
+
# result_video_oss_url = {} # user_id, (list[signed_url), list[oss_path])]
|
|
|
|
|
15 |
|
16 |
def tab_func_template():
|
17 |
prompt = ""
|
|
|
20 |
ref_video_path = None
|
21 |
return ref_video_path, 'prompt_mode'
|
22 |
|
23 |
+
# with open('script.txt', encoding="utf-8") as f:
|
24 |
+
# script_text_to_load_results = f.read()
|
25 |
|
26 |
# def dataset_func(evt: gr.SelectData):
|
27 |
# ref_video_path = evt.value[0]
|
|
|
47 |
def get_user_result_video_list(uuid, date_string, num):
|
48 |
directory='video_generation/Service/'+date_string+'/'+uuid+'/'
|
49 |
for obj in oss2.ObjectIterator(oss_service.bucket, prefix=directory, delimiter='/'):
|
50 |
+
print(f"folder is existed{directory}")
|
51 |
break
|
52 |
else:
|
53 |
+
print(f"folder is not existed: {directory}")
|
54 |
return [],[]
|
55 |
no_check_video_list = []
|
56 |
no_check_timer_list = []
|
57 |
for obj in oss2.ObjectIterator(oss_service.bucket, prefix=directory, delimiter = '/'):
|
58 |
+
if obj.is_prefix(): # folder
|
59 |
file_full_path = obj.key+'result.mp4'
|
60 |
exist = oss_service.bucket.object_exists(file_full_path)
|
61 |
|
|
|
65 |
print(f'tmp_directory = {tmp_directory}')
|
66 |
for obj_xxx in oss2.ObjectIterator(oss_service.bucket, prefix=tmp_directory, delimiter = '/'):
|
67 |
print(f'obj_xxx.key = {obj_xxx.key}')
|
68 |
+
if obj_xxx.is_prefix(): # folder
|
69 |
pass
|
70 |
else:
|
71 |
import re
|
|
|
88 |
mb_num = float(bytes_num) / (1000 ** 2) # MB
|
89 |
# print(f"Object Size: {mb_num} MB")
|
90 |
|
91 |
+
if mb_num > 0.1: # > 100KB
|
92 |
last_modified = object_meta.headers.get('Last-Modified')
|
93 |
# print(f"Last Modified: {last_modified}")
|
94 |
from email.utils import parsedate_to_datetime
|
95 |
+
# HTTP-date to datetime
|
96 |
last_modified_datetime = parsedate_to_datetime(last_modified)
|
97 |
+
# datetime to Unix Time -from 1970-01-01 UTC seconds, nearest is bigger
|
98 |
last_modified_timestamp = int(last_modified_datetime.timestamp())
|
99 |
+
|
|
|
100 |
no_check_video_list.append(file_full_path)
|
101 |
no_check_timer_list.append(last_modified_timestamp)
|
102 |
else:
|
103 |
+
print(f'file size: {file_full_path}')
|
104 |
+
else: # file
|
105 |
+
print(f'not a file: {obj.key}')
|
106 |
+
# last_modified = obj.last_modified # last modify time
|
|
|
107 |
|
108 |
valid_video_list = []
|
109 |
valid_image_list = []
|
110 |
if len(no_check_video_list) > 0:
|
111 |
if len(no_check_video_list) > 1:
|
112 |
# sort by time
|
113 |
+
zipped_lists = zip(no_check_timer_list, no_check_video_list)
|
114 |
+
# big to small, nearest is bigger
|
115 |
+
sorted_pairs = sorted(zipped_lists, key=lambda x: x[0], reverse=True)
|
116 |
list1_sorted, list2_sorted = zip(*sorted_pairs)
|
117 |
no_check_timer_list = list(list1_sorted)
|
118 |
no_check_video_list = list(list2_sorted)
|
119 |
|
120 |
for file_full_path in no_check_video_list:
|
121 |
oss_video_path = "oss://vigen-invi/" + file_full_path
|
122 |
+
print(f'Generated video: {oss_video_path}')
|
123 |
_, video_url = oss_service.sign(oss_video_path, timeout=3600*100)
|
124 |
valid_video_list.append(video_url)
|
125 |
style = "video/snapshot,t_1000,f_jpg,w_544,h_768,m_fast"
|
|
|
142 |
new_image_list = []
|
143 |
if process_status == 'runing':
|
144 |
print(f'process_status: {process_status}')
|
145 |
+
# new_list.append(None)
|
146 |
+
# new_image_list.append(None)
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
date_string = datetime.datetime.now().strftime('%Y-%m-%d')
|
148 |
valid_video_list, valid_image_list = get_user_result_video_list(uuid, date_string, 3)
|
149 |
new_list = new_list + valid_video_list
|
|
|
182 |
new_list.append(None)
|
183 |
new_image_list.append(None)
|
184 |
|
185 |
+
return notes, new_list[0], new_list[1], new_list[2], new_list[3]#, new_image_list[0], new_image_list[1], new_image_list[2], new_image_list[3]
|
186 |
|
187 |
+
with gr.Blocks(title = "Dreamoving",
|
188 |
css='style.css',
|
189 |
theme=gr.themes.Soft(
|
190 |
radius_size=gr.themes.sizes.radius_sm,
|
|
|
193 |
) as demo:
|
194 |
with gr.Row():
|
195 |
gr.HTML(f"""
|
196 |
+
<div id=css_img_dreamoving>
|
197 |
+
<img id=css_img_dreamoving src='{RESOURCES.logo_img0}'>
|
198 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
""")
|
200 |
|
|
|
201 |
if ENABLE_OSS_RESOURCES:
|
202 |
template_videos_to_ref = []
|
203 |
template_video_list = examples['template_video']
|
|
|
206 |
oss_path = "oss://vigen-invi/video_generation/template_video1/" + file_name
|
207 |
_, url = oss_service.sign(oss_path, timeout=3600*100)
|
208 |
template_videos_to_ref.append(url)
|
209 |
+
else:
|
210 |
+
# template_videos = get_dirnames(filePath="./data/template_video", tail=".mp4")
|
211 |
+
template_videos_to_ref = []
|
212 |
+
template_video_list = examples['template_video']
|
213 |
+
for i in range(9):
|
214 |
+
# file_name = os.path.basename(template_videos[i])
|
215 |
+
# file_path = os.path.dirname(template_videos[i])
|
216 |
+
file_name = template_video_list[i]
|
217 |
+
video_path = "./data/template_video/" + file_name
|
218 |
+
template_videos_to_ref.append(video_path)
|
219 |
|
220 |
+
# For the same style generation, after users upload a video, they can click the AI button to automatically generate a prompt.
|
221 |
+
with gr.Accordion(label="🧭 User Guide: It is recommended to read these instructions before using!", open=False):
|
222 |
gr.Markdown("""
|
223 |
+
- ⭐️ 1. Video generation time is about 5 minutes. Due to the high number of concurrent users, the generation task may need to queue. Please click the refresh button and check the prompt message.
|
224 |
+
- ⭐️ 2. If the input image is a cartoon picture, be sure to select "Cartoon Video Generation."
|
225 |
+
- ⭐️ 3. The system retains up to 4 videos generated in the last two days, refreshing at midnight. Please download and save them in time.
|
226 |
+
- ⭐️ 4. System updates generally occur between 7-8 a.m.
|
227 |
""")
|
228 |
|
229 |
+
input_mode = gr.Text(value="template_mode", label="input_mode", visible=False)
|
230 |
with gr.Row():
|
231 |
+
with gr.Column(scale=1):
|
|
|
232 |
with gr.Group(elem_id='show_box'):
|
233 |
+
gr.Markdown("Enter/Select a face image")
|
234 |
with gr.Column():
|
235 |
with gr.Group(elem_id='show_box1'):
|
236 |
+
with gr.Row():
|
|
|
237 |
ref_image = gr.Image(sources='upload', type='filepath', show_label=False, label='输入图片',elem_id='show_window_image')
|
|
|
238 |
gr.Examples(examples['examples_images'], examples_per_page=9, inputs=[ref_image], label='')
|
239 |
|
240 |
+
with gr.Row():
|
241 |
+
model_id = gr.Checkbox(label="Cartoon Video Generation", elem_id='checkbox_0', show_label=False)
|
|
|
242 |
|
243 |
+
with gr.Column():
|
244 |
+
gr.Markdown("Select a mode: Reference-Video/Prompt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
|
246 |
+
with gr.Tab("Guided Style Generation") as tab0:
|
247 |
+
prompt_template = gr.Textbox(placeholder="Enter prompt words to control the generation effect, such as the character, the character's clothing, the scene, etc. Supports input in Chinese/English.",label="Prompt", lines=2,interactive=True,show_label=False, text_align='left')
|
248 |
+
# with gr.Row():
|
249 |
+
# # with gr.Group(elem_id='show_box3'):
|
250 |
+
# # with gr.Group():
|
251 |
+
# with gr.Column(scale=1, min_width=1):
|
252 |
+
# prompt_template = gr.Textbox(placeholder="Enter prompt words to control the generation effect, such as the character, the character's clothing, the scene, etc. Supports input in Chinese/English.", label="Prompt提示词", lines=2,interactive=True,show_label=False, text_align='left')
|
253 |
+
# with gr.Column(scale=1, min_width=1, elem_id='column_button'):
|
254 |
+
# # prompt_caption_01 = gr.Button(value="AI Caption", elem_id='button_param1')
|
255 |
+
# prompt_caption_01 = gr.Button(
|
256 |
+
# value="AI",
|
257 |
+
# elem_classes='btn_texture_font_file'
|
258 |
+
# )
|
259 |
+
|
260 |
with gr.Row():
|
261 |
+
# FIXME: the width/height setting not work here,
|
262 |
+
ref_video = gr.Video(sources='upload', show_label=False, label='Input Video', autoplay=True, elem_id='show_window_video', width=224, height=360)
|
263 |
+
# gr.Examples(examples['template_video'], examples_per_page=9,inputs=[ref_video], label='Template Video')
|
264 |
# dataset_select = gr.Dataset(
|
265 |
+
# label='Template Video',
|
266 |
# components=[gr.Video(visible=False)],
|
267 |
# samples=examples['template_video'],
|
268 |
# samples_per_page=9,
|
|
|
272 |
# # elem_id='template_param',
|
273 |
# )
|
274 |
gr.Examples(
|
275 |
+
label='Template Video',
|
276 |
examples=template_videos_to_ref,
|
277 |
inputs=ref_video,
|
278 |
outputs=[ref_video, prompt_template],
|
|
|
280 |
examples_per_page=9,
|
281 |
cache_examples=True, #run_on_click=True,
|
282 |
)
|
283 |
+
# prompt_template = gr.Textbox(label="Prompt", lines=2,interactive=True,show_label=False, text_align='left')
|
284 |
+
|
285 |
+
|
286 |
+
with gr.Tab("Text-to-Video") as tab1:
|
287 |
+
# prompt = gr.Textbox(label="Prompt", show_label=False, text_align='left')
|
288 |
+
example_prompts= []
|
289 |
+
file = open(ref_video_prompt, 'r')
|
290 |
+
for line in file.readlines():
|
291 |
+
example_prompts.append(line)
|
292 |
+
file.close()
|
293 |
+
prompt = gr.Dropdown(label="Prompt List",choices=example_prompts, show_label=False, allow_custom_value=True)
|
294 |
|
295 |
+
with gr.Row():
|
296 |
+
# Generate Button
|
297 |
+
run_button = gr.Button(value="Result Video", elem_id='button_param')
|
298 |
+
# btn = gr.Button("Result Video").style(full_width=False)
|
299 |
|
300 |
+
with gr.Column(scale=1):
|
301 |
+
# gr.Markdown("Result Video",elem_id='font_style')
|
302 |
with gr.Group(elem_id='show_box2'):
|
303 |
with gr.Row():
|
304 |
+
with gr.Column(scale=1, min_width=1):
|
305 |
+
gr.Markdown("Result Video", elem_id='font_style')
|
306 |
+
with gr.Column(scale=1, min_width=1):
|
307 |
+
user_notes = gr.Textbox(show_label=False, text_align='left', elem_id='text_style11')
|
308 |
+
with gr.Column(scale=1, min_width=1):
|
309 |
+
refresh_button = gr.Button(value="Refresh", elem_id='button_param1')
|
|
|
310 |
|
311 |
with gr.Row():
|
312 |
+
output_video0 = gr.Video(format="mp4", show_label=False, label="Result Video", autoplay=True, elem_id='show_window_result')
|
313 |
+
output_video1 = gr.Video(format="mp4", show_label=False, label="Result Video", autoplay=True,elem_id='show_window_result')
|
|
|
|
|
314 |
with gr.Row():
|
315 |
+
output_video2 = gr.Video(format="mp4", show_label=False, label="Result Video", autoplay=True,elem_id='show_window_result')
|
316 |
+
output_video3 = gr.Video(format="mp4", show_label=False, label="Result Video", autoplay=True,elem_id='show_window_result')
|
|
|
|
|
317 |
|
318 |
uuid = gr.Text(label="modelscope_uuid", visible=False)
|
319 |
request_id = gr.Text(label="modelscope_request_id", visible=False)
|
320 |
|
321 |
+
# Sample Video
|
322 |
+
num_video = 8
|
323 |
+
num_videos_per_row = 4
|
324 |
+
mp4_lists = []
|
|
|
|
|
|
|
|
|
|
|
325 |
if ENABLE_OSS_RESOURCES:
|
326 |
+
mp4_url_list = get_dirnames(filePath="./data/sample_video", tail=".mp4")
|
327 |
+
for i in range(min(num_video, len(mp4_url_list))):
|
328 |
+
file_name = os.path.basename(mp4_url_list[i])
|
|
|
329 |
oss_path = "oss://vigen-invi/video_generation/sample_video/" + file_name
|
330 |
_, video_url = oss_service.sign(oss_path, timeout=3600*100)
|
331 |
+
mp4_lists.append(video_url)
|
332 |
+
else:
|
333 |
+
mp4_lists = get_dirnames(filePath="./data/sample_video", tail=".mp4")
|
334 |
+
|
|
|
335 |
if len(mp4_lists) <= num_video:
|
336 |
num_video = len(mp4_lists)
|
337 |
with gr.Row():
|
338 |
+
gr.Markdown("Sample Video",elem_id='font_style')
|
339 |
with gr.Group(elem_id='show_box'):
|
340 |
with gr.Column():
|
341 |
for i in range(int((num_video+num_videos_per_row-1)/num_videos_per_row)):
|
|
|
350 |
fn=refresh_video,
|
351 |
queue = False,
|
352 |
inputs=[uuid, request_id],
|
353 |
+
outputs=[user_notes, output_video0, output_video1, output_video2, output_video3]
|
|
|
354 |
)
|
355 |
+
|
356 |
+
|
357 |
+
# prompt_caption_01.click(
|
358 |
+
# fn=myHumanGen.click_button_prompt,
|
359 |
+
# queue = False,
|
360 |
+
# inputs=[uuid, request_id, input_mode, ref_image, ref_video, prompt, prompt_template, model_id],
|
361 |
+
# outputs=[prompt_template]
|
362 |
+
# )
|
363 |
+
|
364 |
|
365 |
# dataset_select.select(fn=dataset_func, outputs=[ref_video,prompt_template])
|
366 |
|
367 |
# button触发
|
368 |
+
tab0.select(fn=tab_func_template, outputs=[prompt, input_mode]) # template mode
|
369 |
+
tab1.select(fn=tab_func_prompt, outputs=[ref_video, input_mode]) # prompt mode
|
370 |
|
371 |
def async_process(user_id, request_id, input_mode, ref_image_path, ref_video_path, input_prompt='', prompt_template='',model_id=False):
|
372 |
+
# parm-chheck
|
373 |
check_note_info = myHumanGen.valid_check(user_id, request_id, input_mode, ref_image_path, ref_video_path, input_prompt, prompt_template,model_id)
|
374 |
|
375 |
if check_note_info == '':
|
|
|
376 |
thread = threading.Thread(target=myHumanGen.click_button_func_async, args=(user_id, request_id, input_mode, ref_image_path, ref_video_path, input_prompt, prompt_template,model_id,))
|
377 |
thread.start()
|
378 |
# thread.join()
|
|
|
380 |
|
381 |
return refresh_video(user_id, request_id)
|
382 |
else:
|
383 |
+
notes, video_0, video_1, video_2, video_3 = refresh_video(user_id, request_id)
|
384 |
+
return check_note_info, video_0, video_1, video_2, video_3
|
385 |
|
386 |
+
run_button.click(fn=async_process, inputs=[uuid, request_id, input_mode, ref_image, ref_video, prompt, prompt_template, model_id], outputs=[user_notes, output_video0, output_video1, output_video2, output_video3])
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
|
|
|
|
|
388 |
with gr.Row():
|
389 |
+
# DingTalk
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
gr.HTML(f"""
|
391 |
<div id=css_img_QRCode>
|
392 |
<img id=css_img_QRCode src='{RESOURCES.logo_dingding}'>
|
393 |
</div>
|
394 |
<div id=css_img_QRCode_text>
|
395 |
+
DingTalk Group of Dreamoving
|
396 |
</div>
|
397 |
|
398 |
""")
|
399 |
+
# WeChat
|
400 |
gr.HTML(f"""
|
401 |
<div id=css_img_QRCode>
|
402 |
<img id=css_img_QRCode src='{RESOURCES.logo_wechat}'>
|
403 |
</div>
|
404 |
<div id=css_img_QRCode_text>
|
405 |
+
WeChat Group of Dreamoving
|
406 |
</div>
|
407 |
""")
|
|
|
408 |
|
409 |
+
# version
|
410 |
gr.HTML(f"""
|
411 |
</br>
|
412 |
<div>
|
|
|
414 |
</div>
|
415 |
""")
|
416 |
|
417 |
+
# concurrency_count, concurrency_limit, max_threads
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
demo.queue(api_open=False, max_size=1000).launch(
|
419 |
+
server_name="0.0.0.0", # if os.getenv('GRADIO_LISTEN', '') != '' else "127.0.0.1",
|
420 |
+
share=False,
|
421 |
server_port=7860,
|
422 |
root_path=f"/{os.getenv('GRADIO_PROXY_PATH')}" if os.getenv('GRADIO_PROXY_PATH') else ""
|
423 |
)
|
424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
|