potamides commited on
Commit
8909a16
·
verified ·
1 Parent(s): 4007ec6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -52,7 +52,7 @@ def gen_save_folder(max_size=200):
52
  return new_folder
53
 
54
  @spaces.GPU
55
- def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bbox_z=1.0, hi_res=False):
56
  # Create debug info
57
  debug_info = {
58
  "timestamp": datetime.now().isoformat(),
@@ -61,7 +61,8 @@ def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bb
61
  "bbox_x": bbox_x,
62
  "bbox_y": bbox_y,
63
  "bbox_z": bbox_z,
64
- "hi_res": hi_res
 
65
  }
66
 
67
  # Save to persistent storage
@@ -72,9 +73,17 @@ def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bb
72
  #with open(prompt_file, "a") as f:
73
  # f.write(json.dumps(debug_info) + "\n")
74
 
75
- print(f"prompt: {input_prompt}, use_bbox: {use_bbox}, bbox_x: {bbox_x}, bbox_y: {bbox_y}, bbox_z: {bbox_z}, hi_res: {hi_res}")
 
 
 
 
 
 
 
 
76
 
77
- if "engine_fast" not in GLOBAL_STATE:
78
  config_path = GLOBAL_STATE["config_path"]
79
  gpt_ckpt_path = "./model_weights/shape_gpt.safetensors"
80
  shape_ckpt_path = "./model_weights/shape_tokenizer.safetensors"
@@ -95,7 +104,7 @@ def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bb
95
  normalized_bbox = normalize_bbox(bbox_size) if bbox_size is not None else None
96
 
97
  resolution_base = 9.0 if hi_res else 8.0
98
- mesh_v_f = GLOBAL_STATE["engine_fast"].t2s([input_prompt], use_kv_cache=True, resolution_base=resolution_base, bounding_box_xyz=normalized_bbox)
99
  # save output
100
  vertices, faces = mesh_v_f[0][0], mesh_v_f[0][1]
101
 
@@ -163,6 +172,15 @@ def build_interface():
163
  )
164
 
165
  hi_res = gr.Checkbox(label="Hi-Res", value=False)
 
 
 
 
 
 
 
 
 
166
  with gr.Row():
167
  submit_button = gr.Button("Submit", variant="primary")
168
  with gr.Column(scale=3):
@@ -178,7 +196,8 @@ def build_interface():
178
  bbox_x,
179
  bbox_y,
180
  bbox_z,
181
- hi_res
 
182
  ],
183
  outputs=[
184
  model3d
 
52
  return new_folder
53
 
54
  @spaces.GPU
55
+ def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bbox_z=1.0, hi_res=False, guidance_scale=3.0):
56
  # Create debug info
57
  debug_info = {
58
  "timestamp": datetime.now().isoformat(),
 
61
  "bbox_x": bbox_x,
62
  "bbox_y": bbox_y,
63
  "bbox_z": bbox_z,
64
+ "hi_res": hi_res,
65
+ "guidance_scale": guidance_scale
66
  }
67
 
68
  # Save to persistent storage
 
73
  #with open(prompt_file, "a") as f:
74
  # f.write(json.dumps(debug_info) + "\n")
75
 
76
+ print(f"prompt: {input_prompt}, use_bbox: {use_bbox}, bbox_x: {bbox_x}, bbox_y: {bbox_y}, bbox_z: {bbox_z}, hi_res: {hi_res}, guidance_scale: {guidance_scale}")
77
+
78
+ # EngineFast captures its CUDA graph for the doubled (cond+uncond) batch, so a
79
+ # guidance scale of 0 (fully disabling CFG) is not supported by the fast engine.
80
+ if guidance_scale <= 0.0:
81
+ raise gr.Error(
82
+ "Guidance scale must be greater than 0 with the fast engine. "
83
+ "Fully disabling classifier-free guidance (0.0) requires the non-fast Engine."
84
+ )
85
 
86
+ if "engine_fast" not in GLOBAL_STATE:
87
  config_path = GLOBAL_STATE["config_path"]
88
  gpt_ckpt_path = "./model_weights/shape_gpt.safetensors"
89
  shape_ckpt_path = "./model_weights/shape_tokenizer.safetensors"
 
104
  normalized_bbox = normalize_bbox(bbox_size) if bbox_size is not None else None
105
 
106
  resolution_base = 9.0 if hi_res else 8.0
107
+ mesh_v_f = GLOBAL_STATE["engine_fast"].t2s([input_prompt], use_kv_cache=True, resolution_base=resolution_base, bounding_box_xyz=normalized_bbox, guidance_scale=guidance_scale)
108
  # save output
109
  vertices, faces = mesh_v_f[0][0], mesh_v_f[0][1]
110
 
 
172
  )
173
 
174
  hi_res = gr.Checkbox(label="Hi-Res", value=False)
175
+
176
+ guidance_scale = gr.Slider(
177
+ minimum=0.0,
178
+ maximum=10.0,
179
+ step=0.5,
180
+ value=3.0,
181
+ label="Guidance Scale",
182
+ info="Classifier-free guidance strength. Higher = stronger prompt adherence. 0 disables CFG (not supported by the fast engine).",
183
+ )
184
  with gr.Row():
185
  submit_button = gr.Button("Submit", variant="primary")
186
  with gr.Column(scale=3):
 
196
  bbox_x,
197
  bbox_y,
198
  bbox_z,
199
+ hi_res,
200
+ guidance_scale
201
  ],
202
  outputs=[
203
  model3d