Spaces:
Running
on
L40S
Running
on
L40S
Upload app_hg.py with huggingface_hub
Browse files
app_hg.py
CHANGED
@@ -19,7 +19,7 @@
|
|
19 |
# optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
|
20 |
# fine-tuning enabling code and other elements of the foregoing made publicly available
|
21 |
# by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
|
22 |
-
|
23 |
import os
|
24 |
import warnings
|
25 |
import argparse
|
@@ -151,6 +151,7 @@ worker_v23 = Views2Mesh(
|
|
151 |
)
|
152 |
worker_gif = GifRenderer(args.device)
|
153 |
|
|
|
154 |
def stage_0_t2i(text, image, seed, step):
|
155 |
os.makedirs('./outputs/app_output', exist_ok=True)
|
156 |
exists = set(int(_) for _ in os.listdir('./outputs/app_output') if not _.startswith("."))
|
@@ -161,7 +162,7 @@ def stage_0_t2i(text, image, seed, step):
|
|
161 |
save_folder = f'./outputs/app_output/{cur_id}'
|
162 |
os.makedirs(save_folder, exist_ok=True)
|
163 |
|
164 |
-
dst = save_folder
|
165 |
|
166 |
if not text:
|
167 |
if image is None:
|
@@ -174,7 +175,8 @@ def stage_0_t2i(text, image, seed, step):
|
|
174 |
image.save(dst)
|
175 |
dst = worker_xbg(image, save_folder)
|
176 |
return dst, save_folder
|
177 |
-
|
|
|
178 |
def stage_1_xbg(image, save_folder):
|
179 |
if isinstance(image, str):
|
180 |
image = Image.open(image)
|
@@ -183,6 +185,7 @@ def stage_1_xbg(image, save_folder):
|
|
183 |
rgba.save(dst)
|
184 |
return dst
|
185 |
|
|
|
186 |
def stage_2_i2v(image, seed, step, save_folder):
|
187 |
if isinstance(image, str):
|
188 |
image = Image.open(image)
|
@@ -197,6 +200,7 @@ def stage_2_i2v(image, seed, step, save_folder):
|
|
197 |
show_img = Image.fromarray(show_img)
|
198 |
return views_img, cond_img, show_img
|
199 |
|
|
|
200 |
def stage_3_v23(
|
201 |
views_pil,
|
202 |
cond_pil,
|
@@ -219,6 +223,7 @@ def stage_3_v23(
|
|
219 |
)
|
220 |
return obj_dst, glb_dst
|
221 |
|
|
|
222 |
def stage_4_gif(obj_dst, save_folder, do_render_gif=True):
|
223 |
if not do_render_gif: return None
|
224 |
gif_dst = save_folder + '/output.gif'
|
|
|
19 |
# optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
|
20 |
# fine-tuning enabling code and other elements of the foregoing made publicly available
|
21 |
# by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
|
22 |
+
import spaces
|
23 |
import os
|
24 |
import warnings
|
25 |
import argparse
|
|
|
151 |
)
|
152 |
worker_gif = GifRenderer(args.device)
|
153 |
|
154 |
+
@spaces.GPU
|
155 |
def stage_0_t2i(text, image, seed, step):
|
156 |
os.makedirs('./outputs/app_output', exist_ok=True)
|
157 |
exists = set(int(_) for _ in os.listdir('./outputs/app_output') if not _.startswith("."))
|
|
|
162 |
save_folder = f'./outputs/app_output/{cur_id}'
|
163 |
os.makedirs(save_folder, exist_ok=True)
|
164 |
|
165 |
+
dst = os.path.join(save_folder, 'img.png')
|
166 |
|
167 |
if not text:
|
168 |
if image is None:
|
|
|
175 |
image.save(dst)
|
176 |
dst = worker_xbg(image, save_folder)
|
177 |
return dst, save_folder
|
178 |
+
|
179 |
+
@spaces.GPU
|
180 |
def stage_1_xbg(image, save_folder):
|
181 |
if isinstance(image, str):
|
182 |
image = Image.open(image)
|
|
|
185 |
rgba.save(dst)
|
186 |
return dst
|
187 |
|
188 |
+
@spaces.GPU
|
189 |
def stage_2_i2v(image, seed, step, save_folder):
|
190 |
if isinstance(image, str):
|
191 |
image = Image.open(image)
|
|
|
200 |
show_img = Image.fromarray(show_img)
|
201 |
return views_img, cond_img, show_img
|
202 |
|
203 |
+
@spaces.GPU
|
204 |
def stage_3_v23(
|
205 |
views_pil,
|
206 |
cond_pil,
|
|
|
223 |
)
|
224 |
return obj_dst, glb_dst
|
225 |
|
226 |
+
@spaces.GPU
|
227 |
def stage_4_gif(obj_dst, save_folder, do_render_gif=True):
|
228 |
if not do_render_gif: return None
|
229 |
gif_dst = save_folder + '/output.gif'
|