zzw
commited on
Commit
·
3a8e465
1
Parent(s):
42643f5
examples
Browse files- .gitattributes +1 -0
- app.py +34 -26
- test32.mp4 +3 -0
- title.md +1 -4
- utils.py +5 -4
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
test32.mp4 filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
@@ -20,8 +20,13 @@ with open("sorted.json", "r") as f:
|
|
20 |
styles = list(style_dicts.keys())
|
21 |
style_images = {k: v['thumbnailUrl'] for k, v in style_dicts.items() if v is not None}
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
print("IP address:", clientHost)
|
26 |
return clientHost
|
27 |
|
@@ -40,16 +45,15 @@ def check_ip_limit(client_ip):
|
|
40 |
else:
|
41 |
return False
|
42 |
|
43 |
-
def fn(in_video, style, aspect_ratio,
|
44 |
-
client_host = get_client_info(request)
|
45 |
-
flag = check_ip_limit(client_host)
|
46 |
-
if not flag:
|
47 |
-
raise gr.Error(f"Exceed the request limit of 1 requests per five minute.")
|
48 |
-
|
49 |
-
print(f"Received video: {in_video}, aspect_ratio: {aspect_ratio}, style: {style}, transfer_duration: {transfer_duration}")
|
50 |
|
|
|
|
|
51 |
if in_video is None:
|
52 |
raise Exception("input_video is None")
|
|
|
|
|
|
|
53 |
|
54 |
if aspect_ratio not in ["16:9", "9:16", "1:1"]:
|
55 |
raise Exception('aspect_ratio not in ["16:9", "9:16", "1:1"]')
|
@@ -73,7 +77,7 @@ def fn(in_video, style, aspect_ratio, transfer_duration, request: gr.Request):
|
|
73 |
res = None
|
74 |
try:
|
75 |
global_lock.acquire()
|
76 |
-
res = processing(in_video, width, height, style_id, transfer_duration)
|
77 |
if not res:
|
78 |
raise Exception("Processing failed")
|
79 |
finally:
|
@@ -92,8 +96,15 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
92 |
with gr.Tab("Video Processing"):
|
93 |
with gr.Row():
|
94 |
in_video = gr.Video(label="1. Input Video (Please provide a clear video clip)", interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
out_video = gr.Video(label="Final Output Video")
|
96 |
|
|
|
97 |
with gr.Row():
|
98 |
style = gr.Radio(
|
99 |
choices=styles,
|
@@ -113,32 +124,29 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
113 |
|
114 |
style.change(fn=update_preview, inputs=style, outputs=preview)
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
aspect_ratio = gr.Radio(["16:9", "9:16", "1:1"], label="3. Aspect Ratio(Width:Height)", value="16:9", interactive=True)
|
119 |
-
transfer_duration = gr.Slider(
|
120 |
-
minimum=0,
|
121 |
-
maximum=3,
|
122 |
-
step=1,
|
123 |
-
value=3,
|
124 |
-
label="Transfer Duration (seconds), for more than 3 seconds, please join our Discord(https://discord.gg/cN8geBsBmu) or website",
|
125 |
-
interactive=True
|
126 |
-
)
|
127 |
-
submit_button = gr.Button("Generate", interactive=True)
|
128 |
|
129 |
examples = gr.Examples(
|
130 |
[
|
131 |
-
["test32.mp4", "ClayStyle1", "9:16" ],
|
132 |
-
["test32.mp4", "3D P1", "9:16" ],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
],
|
134 |
-
inputs=[in_video, style, aspect_ratio,
|
135 |
outputs=[out_video],
|
136 |
fn=fn,
|
137 |
)
|
138 |
|
139 |
submit_button.click(
|
140 |
fn,
|
141 |
-
inputs=[in_video, style, aspect_ratio,
|
142 |
outputs=[out_video],
|
143 |
)
|
144 |
gr.HTML(load_description("end.md"))
|
|
|
20 |
styles = list(style_dicts.keys())
|
21 |
style_images = {k: v['thumbnailUrl'] for k, v in style_dicts.items() if v is not None}
|
22 |
|
23 |
+
# results_map = {
|
24 |
+
# "test32.mp4ClayStyle19:16": "test32.mp4",
|
25 |
+
# "test32.mp43D P19:16": "test32.mp4",
|
26 |
+
# }
|
27 |
+
def get_client_info():
|
28 |
+
request = gr.Request()
|
29 |
+
clientHost = request
|
30 |
print("IP address:", clientHost)
|
31 |
return clientHost
|
32 |
|
|
|
45 |
else:
|
46 |
return False
|
47 |
|
48 |
+
def fn(in_video, style, aspect_ratio, prompt):
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
print(f"Received video: {in_video}, aspect_ratio: {aspect_ratio}, style: {style}")
|
51 |
+
|
52 |
if in_video is None:
|
53 |
raise Exception("input_video is None")
|
54 |
+
# input_str = "".join([str(item) for item in [in_video, style, aspect_ratio]])
|
55 |
+
# if input_str in results_map:
|
56 |
+
# return results_map[input_str]
|
57 |
|
58 |
if aspect_ratio not in ["16:9", "9:16", "1:1"]:
|
59 |
raise Exception('aspect_ratio not in ["16:9", "9:16", "1:1"]')
|
|
|
77 |
res = None
|
78 |
try:
|
79 |
global_lock.acquire()
|
80 |
+
res = processing(in_video, width, height, style_id, transfer_duration, prompt)
|
81 |
if not res:
|
82 |
raise Exception("Processing failed")
|
83 |
finally:
|
|
|
96 |
with gr.Tab("Video Processing"):
|
97 |
with gr.Row():
|
98 |
in_video = gr.Video(label="1. Input Video (Please provide a clear video clip)", interactive=True)
|
99 |
+
|
100 |
+
aspect_ratio = gr.Radio(["16:9", "9:16", "1:1"], label="3. Aspect Ratio(Width:Height)", value="16:9", interactive=True)
|
101 |
+
|
102 |
+
prompt = gr.Textbox(label="4. Prompt", value="a character with cute face")
|
103 |
+
|
104 |
+
|
105 |
out_video = gr.Video(label="Final Output Video")
|
106 |
|
107 |
+
|
108 |
with gr.Row():
|
109 |
style = gr.Radio(
|
110 |
choices=styles,
|
|
|
124 |
|
125 |
style.change(fn=update_preview, inputs=style, outputs=preview)
|
126 |
|
127 |
+
submit_button = gr.Button("Generate", interactive=True, variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
examples = gr.Examples(
|
130 |
[
|
131 |
+
["test32.mp4", "ClayStyle1", "9:16", "a girl with cute face is walking"],
|
132 |
+
["test32.mp4", "3D P1", "9:16", "a girl with cute face is walking" ],
|
133 |
+
["test32.mp4", "FlatanimeV4-3", "9:16", "a girl with cute face is walking" ],
|
134 |
+
["test32.mp4", "FlatanimeV4 Delicated", "9:16", "a girl with cute face is walking" ],
|
135 |
+
["test32.mp4", "illustrationV4-1", "9:16", "a girl with cute face is walking" ],
|
136 |
+
["test32.mp4", "Child Crayon Drawing", "9:16", "a girl with cute face is walking" ],
|
137 |
+
["test32.mp4", "Pixels", "9:16", "a girl with cute face is walking" ],
|
138 |
+
["test32.mp4", "Color Ink Painting", "9:16", "a girl with cute face is walking" ],
|
139 |
+
["test32.mp4", "cutefaceV4 style1", "9:16", "a girl with cute face is walking" ],
|
140 |
+
["test32.mp4", "flatanime-gibli", "9:16", "a girl with cute face is walking" ],
|
141 |
],
|
142 |
+
inputs=[in_video, style, aspect_ratio, prompt],
|
143 |
outputs=[out_video],
|
144 |
fn=fn,
|
145 |
)
|
146 |
|
147 |
submit_button.click(
|
148 |
fn,
|
149 |
+
inputs=[in_video, style, aspect_ratio, prompt],
|
150 |
outputs=[out_video],
|
151 |
)
|
152 |
gr.HTML(load_description("end.md"))
|
test32.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2c29cb70a806850c1a347f829b07bb4a0276fd0c99aa236181e73b935ee189e0
|
3 |
+
size 1430465
|
title.md
CHANGED
@@ -15,10 +15,7 @@
|
|
15 |
</div>
|
16 |
<br>
|
17 |
<div style=" font-size: 14px;">
|
18 |
-
<p>1. Select a video clip </p>
|
19 |
-
<p>2. Select a style </p>
|
20 |
-
<p>3. Select an aspect ratio </p>
|
21 |
-
<p>4. click Generate button </p>
|
22 |
</div>
|
23 |
</div>
|
24 |
</div>
|
|
|
15 |
</div>
|
16 |
<br>
|
17 |
<div style=" font-size: 14px;">
|
18 |
+
<p>1. Select a video clip; 2. Select a style; 3. Select an aspect ratio; 4. prompt; 5. click Generate button. </p>
|
|
|
|
|
|
|
19 |
</div>
|
20 |
</div>
|
21 |
</div>
|
utils.py
CHANGED
@@ -103,7 +103,7 @@ def upload_video(file):
|
|
103 |
return False
|
104 |
return upload_res.get('data')
|
105 |
|
106 |
-
def generate(item_id, style_id, width, height, ):
|
107 |
endpoint = get_endpoint()
|
108 |
url = endpoint + "/api/job/common"
|
109 |
payload = json.dumps({
|
@@ -111,7 +111,8 @@ def generate(item_id, style_id, width, height, ):
|
|
111 |
"item_id": item_id,
|
112 |
"seed": 11111,
|
113 |
"width": width,
|
114 |
-
"height": height
|
|
|
115 |
},
|
116 |
"unit": 3,
|
117 |
"use_credit_type": "credit",
|
@@ -171,7 +172,7 @@ def download_file(url):
|
|
171 |
else:
|
172 |
return None
|
173 |
|
174 |
-
def processing(in_video, width, height, style_id,transfer_duration):
|
175 |
videoRes = upload_video(in_video)
|
176 |
if not videoRes:
|
177 |
return None
|
@@ -182,7 +183,7 @@ def processing(in_video, width, height, style_id,transfer_duration):
|
|
182 |
req_access = False
|
183 |
try_times = 1000
|
184 |
for i in range(try_times):
|
185 |
-
generate_result = generate(videoId, style_id, width, height)
|
186 |
if not generate_result:
|
187 |
time.sleep(8)
|
188 |
continue
|
|
|
103 |
return False
|
104 |
return upload_res.get('data')
|
105 |
|
106 |
+
def generate(item_id, style_id, width, height, prompt):
|
107 |
endpoint = get_endpoint()
|
108 |
url = endpoint + "/api/job/common"
|
109 |
payload = json.dumps({
|
|
|
111 |
"item_id": item_id,
|
112 |
"seed": 11111,
|
113 |
"width": width,
|
114 |
+
"height": height,
|
115 |
+
"prompt": prompt
|
116 |
},
|
117 |
"unit": 3,
|
118 |
"use_credit_type": "credit",
|
|
|
172 |
else:
|
173 |
return None
|
174 |
|
175 |
+
def processing(in_video, width, height, style_id,transfer_duration, prompt):
|
176 |
videoRes = upload_video(in_video)
|
177 |
if not videoRes:
|
178 |
return None
|
|
|
183 |
req_access = False
|
184 |
try_times = 1000
|
185 |
for i in range(try_times):
|
186 |
+
generate_result = generate(videoId, style_id, width, height, prompt)
|
187 |
if not generate_result:
|
188 |
time.sleep(8)
|
189 |
continue
|