Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
e0263b2
·
1 Parent(s): 81d5d11

Refactor gen_image function in app.py to create a temporary GLB file with a proper extension and return its path. This change enhances file management by ensuring the generated file is correctly handled and simplifies the cleanup process.

Browse files
Files changed (1) hide show
  1. app.py +13 -7
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()
@@ -243,4 +249,4 @@ with gr.Blocks() as demo:
243
  inputs=inputs,
244
  outputs=outputs,
245
  )
246
- demo.queue().launch()
 
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()
 
249
  inputs=inputs,
250
  outputs=outputs,
251
  )
252
+ demo.queue().launch()