Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
3ae641b
·
1 Parent(s): 748d9f5

Enhance gen_image function in app.py to return base64 encoded GLB data alongside generated images. Clean up argument parsing by removing unused stage1 and stage2 config options in parser. Update requirements.txt to specify gradio version for compatibility.

Browse files
Files changed (2) hide show
  1. app.py +11 -14
  2. requirements.txt +2 -2
app.py CHANGED
@@ -93,7 +93,9 @@ def preprocess_image(image, background_choice, foreground_ratio, backgroud_color
93
  image = add_background(image, backgroud_color)
94
  return image.convert("RGB")
95
 
 
96
  @spaces.GPU
 
97
  def gen_image(input_image, seed, scale, step):
98
  global pipeline, model, args
99
  pipeline.set_seed(seed)
@@ -102,24 +104,19 @@ def gen_image(input_image, seed, scale, step):
102
  stage2_images = rt_dict["stage2_images"]
103
  np_imgs = np.concatenate(stage1_images, 1)
104
  np_xyzs = np.concatenate(stage2_images, 1)
105
-
106
  glb_path = generate3d(model, np_imgs, np_xyzs, args.device)
107
- return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), glb_path#, obj_path
 
 
 
 
 
 
 
108
 
109
 
110
  parser = argparse.ArgumentParser()
111
- parser.add_argument(
112
- "--stage1_config",
113
- type=str,
114
- default="configs/nf7_v3_SNR_rd_size_stroke.yaml",
115
- help="config for stage1",
116
- )
117
- parser.add_argument(
118
- "--stage2_config",
119
- type=str,
120
- default="configs/stage2-v2-snr.yaml",
121
- help="config for stage2",
122
- )
123
 
124
  parser.add_argument("--device", type=str, default="cuda")
125
  args = parser.parse_args()
 
93
  image = add_background(image, backgroud_color)
94
  return image.convert("RGB")
95
 
96
+
97
  @spaces.GPU
98
+
99
  def gen_image(input_image, seed, scale, step):
100
  global pipeline, model, args
101
  pipeline.set_seed(seed)
 
104
  stage2_images = rt_dict["stage2_images"]
105
  np_imgs = np.concatenate(stage1_images, 1)
106
  np_xyzs = np.concatenate(stage2_images, 1)
107
+
108
  glb_path = generate3d(model, np_imgs, np_xyzs, args.device)
109
+
110
+ # Read the GLB file and encode it in base64
111
+ with open(glb_path, 'rb') as f:
112
+ glb_bytes = f.read()
113
+ encoded_glb = 'data:model/gltf-binary;base64,' + base64.b64encode(glb_bytes).decode('utf-8')
114
+
115
+ # Return images and the encoded GLB data
116
+ return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), encoded_glb
117
 
118
 
119
  parser = argparse.ArgumentParser()
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  parser.add_argument("--device", type=str, default="cuda")
122
  args = parser.parse_args()
requirements.txt CHANGED
@@ -1,5 +1,4 @@
1
- gradio
2
- huggingface-hub
3
  diffusers==0.24.0
4
  einops==0.7.0
5
  Pillow==10.1.0
@@ -8,6 +7,7 @@ open-clip-torch==2.7.0
8
  opencv-contrib-python-headless==4.9.0.80
9
  opencv-python-headless==4.9.0.80
10
  xformers
 
11
  omegaconf
12
  rembg
13
  git+https://github.com/NVlabs/nvdiffrast
 
1
+ huggingface-hub == 0.19.4
 
2
  diffusers==0.24.0
3
  einops==0.7.0
4
  Pillow==10.1.0
 
7
  opencv-contrib-python-headless==4.9.0.80
8
  opencv-python-headless==4.9.0.80
9
  xformers
10
+ gradio==0.16.0
11
  omegaconf
12
  rembg
13
  git+https://github.com/NVlabs/nvdiffrast