Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -165,7 +165,8 @@ def preprocess(input_image, do_remove_background, foreground_ratio):
|
|
| 165 |
image = input_image
|
| 166 |
if image.mode == "RGBA":
|
| 167 |
image = fill_background(image)
|
| 168 |
-
torch.cuda.synchronize()
|
|
|
|
| 169 |
return image
|
| 170 |
|
| 171 |
# @spaces.GPU
|
|
@@ -182,7 +183,8 @@ def generate(image, mc_resolution, formats=["obj", "glb"]):
|
|
| 182 |
mesh_path_obj = tempfile.NamedTemporaryFile(suffix=f".obj", delete=False)
|
| 183 |
mesh.apply_scale([-1, 1, 1]) # Otherwise the visualized .obj will be flipped
|
| 184 |
mesh.export(mesh_path_obj.name)
|
| 185 |
-
torch.cuda.synchronize()
|
|
|
|
| 186 |
return mesh_path_obj.name, mesh_path_glb.name
|
| 187 |
|
| 188 |
def upload_file_to_s3(file_path, bucket_name, object_name=None):
|
|
@@ -239,7 +241,8 @@ async def process_image(
|
|
| 239 |
object_name_2 = f'object_{timestamp}_2.glb'
|
| 240 |
|
| 241 |
if upload_file_to_s3(mesh_name_obj, 'framebucket3d',object_name) and upload_file_to_s3(mesh_name_glb, 'framebucket3d',object_name_2):
|
| 242 |
-
|
|
|
|
| 243 |
return {
|
| 244 |
"obj_path": f"https://framebucket3d.s3.amazonaws.com/{object_name}",
|
| 245 |
"glb_path": f"https://framebucket3d.s3.amazonaws.com/{object_name_2}"
|
|
|
|
| 165 |
image = input_image
|
| 166 |
if image.mode == "RGBA":
|
| 167 |
image = fill_background(image)
|
| 168 |
+
torch.cuda.synchronize() # Wait for all CUDA operations to complete
|
| 169 |
+
torch.cuda.empty_cache()
|
| 170 |
return image
|
| 171 |
|
| 172 |
# @spaces.GPU
|
|
|
|
| 183 |
mesh_path_obj = tempfile.NamedTemporaryFile(suffix=f".obj", delete=False)
|
| 184 |
mesh.apply_scale([-1, 1, 1]) # Otherwise the visualized .obj will be flipped
|
| 185 |
mesh.export(mesh_path_obj.name)
|
| 186 |
+
torch.cuda.synchronize() # Ensure all CUDA operations are complete before clearing cache
|
| 187 |
+
torch.cuda.empty_cache()
|
| 188 |
return mesh_path_obj.name, mesh_path_glb.name
|
| 189 |
|
| 190 |
def upload_file_to_s3(file_path, bucket_name, object_name=None):
|
|
|
|
| 241 |
object_name_2 = f'object_{timestamp}_2.glb'
|
| 242 |
|
| 243 |
if upload_file_to_s3(mesh_name_obj, 'framebucket3d',object_name) and upload_file_to_s3(mesh_name_glb, 'framebucket3d',object_name_2):
|
| 244 |
+
torch.cuda.synchronize() # Wait for all CUDA operations to complete
|
| 245 |
+
torch.cuda.empty_cache()
|
| 246 |
return {
|
| 247 |
"obj_path": f"https://framebucket3d.s3.amazonaws.com/{object_name}",
|
| 248 |
"glb_path": f"https://framebucket3d.s3.amazonaws.com/{object_name_2}"
|