Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
57a43ce
·
1 Parent(s): 65f401b

Refactor gen_image function in app.py to use a temporary file for GLB data instead of base64 encoding. This change improves file handling and returns the path to the temporary GLB file.

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -108,13 +108,19 @@ def gen_image(input_image, seed, scale, step):
108
 
109
  glb_path = generate3d(model, np_imgs, np_xyzs, args.device)
110
 
111
- # Read the GLB file and encode it in base64
112
- with open(glb_path, 'rb') as f:
113
- glb_bytes = f.read()
114
- encoded_glb = 'data:model/gltf-binary;base64,' + base64.b64encode(glb_bytes).decode('utf-8')
115
 
116
- # Return images and the encoded GLB data
117
- return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), encoded_glb
 
 
 
 
 
 
 
118
 
119
 
120
  parser = argparse.ArgumentParser()
 
108
 
109
  glb_path = generate3d(model, np_imgs, np_xyzs, args.device)
110
 
111
+ # Create a temporary file with a proper name for the GLB data
112
+ import tempfile
113
+ import shutil
 
114
 
115
+ # Create a temporary file with a proper extension
116
+ temp_glb = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
117
+ temp_glb.close()
118
+
119
+ # Copy the generated GLB file to our temporary file
120
+ shutil.copy2(glb_path, temp_glb.name)
121
+
122
+ # Return images and the path to the temporary GLB file
123
+ return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), temp_glb.name
124
 
125
 
126
  parser = argparse.ArgumentParser()