Spaces:
mashroo
/
Running on Zero

YoussefAnso commited on
Commit
0d60bce
·
1 Parent(s): dbc79a8

Enhance Gradio interface by disabling API endpoint generation for the Blocks interface and button actions, while implementing Spaces-specific launch settings to improve compatibility and performance in different environments.

Browse files
Files changed (1) hide show
  1. app.py +36 -14
app.py CHANGED
@@ -212,9 +212,12 @@ def generate(image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps):
212
  processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
213
  return gen_image(processed, seed_val, guidance, steps)
214
 
215
- # Create a Blocks interface
216
- with gr.Blocks(analytics_enabled=False) as demo:
217
- gr.Markdown("# CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model")
 
 
 
218
  gr.Markdown(_DESCRIPTION)
219
 
220
  with gr.Row():
@@ -248,25 +251,44 @@ with gr.Blocks(analytics_enabled=False) as demo:
248
  output_ccm = gr.Image(interactive=False, label="Output CCM image")
249
  output_glb = gr.Model3D(label="Output GLB", interactive=False)
250
 
251
- # Connect the button click event
252
  generate_btn.click(
253
  fn=generate,
254
  inputs=[input_image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps],
255
  outputs=[output_rgb, output_ccm, output_glb],
256
- concurrency_limit=1
 
257
  )
258
 
259
- # Add examples
260
  gr.Examples(
261
  examples=[[os.path.join("examples", i)] for i in os.listdir("examples")],
262
- inputs=input_image
 
263
  )
264
 
265
- # Launch with minimal settings
266
  if __name__ == "__main__":
267
- demo.launch(
268
- server_name="0.0.0.0",
269
- server_port=7860,
270
- show_error=True,
271
- max_threads=1
272
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
213
  return gen_image(processed, seed_val, guidance, steps)
214
 
215
+ # Create a Blocks interface with API info disabled
216
+ with gr.Blocks(
217
+ analytics_enabled=False,
218
+ api_name=None, # Disable API endpoint generation
219
+ title="CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model"
220
+ ) as demo:
221
  gr.Markdown(_DESCRIPTION)
222
 
223
  with gr.Row():
 
251
  output_ccm = gr.Image(interactive=False, label="Output CCM image")
252
  output_glb = gr.Model3D(label="Output GLB", interactive=False)
253
 
254
+ # Connect the button click event with API name disabled
255
  generate_btn.click(
256
  fn=generate,
257
  inputs=[input_image, bg_choice, fg_ratio, bg_color, seed_val, guidance, steps],
258
  outputs=[output_rgb, output_ccm, output_glb],
259
+ concurrency_limit=1,
260
+ api_name=None # Disable API endpoint for this event
261
  )
262
 
263
+ # Add examples without caching
264
  gr.Examples(
265
  examples=[[os.path.join("examples", i)] for i in os.listdir("examples")],
266
+ inputs=input_image,
267
+ cache_examples=False # Disable example caching
268
  )
269
 
270
+ # Launch with Spaces-specific settings
271
  if __name__ == "__main__":
272
+ import os
273
+ from spaces.zero.gradio import launch # Use Spaces specific launch function
274
+
275
+ if os.environ.get("SPACE_ID") is not None: # We're running on Hugging Face Spaces
276
+ launch(
277
+ demo,
278
+ server_name="0.0.0.0",
279
+ server_port=7860,
280
+ show_error=True,
281
+ enable_queue=True,
282
+ max_threads=1,
283
+ api_name=None, # Disable API endpoint generation
284
+ share=False, # Don't use share on Spaces
285
+ prevent_thread_lock=True # Prevent thread lock issues
286
+ )
287
+ else: # Local development
288
+ demo.launch(
289
+ server_name="0.0.0.0",
290
+ server_port=7860,
291
+ show_error=True,
292
+ share=True, # Only use share=True for local development
293
+ api_name=None # Disable API endpoint generation
294
+ )