Commit
·
71312a3
1
Parent(s):
f2cf584
Refactor gen_image function in app.py to utilize NamedTemporaryFile for GLB file creation, enhancing file management and simplifying cleanup. Return the path of the temporary GLB file directly.
Browse files
app.py
CHANGED
@@ -110,24 +110,16 @@ def gen_image(input_image, seed, scale, step):
|
|
110 |
# Create a temporary file with a proper name for the GLB data
|
111 |
import tempfile
|
112 |
import shutil
|
113 |
-
import os
|
114 |
|
115 |
-
# Create a temporary file with a proper extension
|
116 |
-
|
117 |
-
|
118 |
-
temp_glb = os.path.join(temp_dir, f"model_{seed}.glb")
|
119 |
|
120 |
# Copy the generated GLB file to our temporary file
|
121 |
-
shutil.copy2(glb_path, temp_glb)
|
122 |
-
|
123 |
-
# Clean up the original GLB file
|
124 |
-
try:
|
125 |
-
os.remove(glb_path)
|
126 |
-
except:
|
127 |
-
pass
|
128 |
|
129 |
# Return images and the path to the temporary GLB file
|
130 |
-
return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), temp_glb
|
131 |
|
132 |
|
133 |
parser = argparse.ArgumentParser()
|
|
|
110 |
# Create a temporary file with a proper name for the GLB data
|
111 |
import tempfile
|
112 |
import shutil
|
|
|
113 |
|
114 |
+
# Create a temporary file with a proper extension
|
115 |
+
temp_glb = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
|
116 |
+
temp_glb.close()
|
|
|
117 |
|
118 |
# Copy the generated GLB file to our temporary file
|
119 |
+
shutil.copy2(glb_path, temp_glb.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
# Return images and the path to the temporary GLB file
|
122 |
+
return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), temp_glb.name
|
123 |
|
124 |
|
125 |
parser = argparse.ArgumentParser()
|