Commit
·
b96430e
1
Parent(s):
c1d0660
Refactor Gradio interface to implement concurrency limits directly on the event listener, enhancing performance and simplifying the launch process for Hugging Face Spaces.
Browse files
app.py
CHANGED
@@ -262,6 +262,7 @@ with gr.Blocks(analytics_enabled=False) as demo: # Disable analytics to reduce
|
|
262 |
processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
|
263 |
return gen_image(processed, seed_val, guidance, steps)
|
264 |
|
|
|
265 |
text_button.click(
|
266 |
fn=generate,
|
267 |
inputs=[
|
@@ -278,14 +279,15 @@ with gr.Blocks(analytics_enabled=False) as demo: # Disable analytics to reduce
|
|
278 |
xyz_output,
|
279 |
output_model
|
280 |
],
|
281 |
-
api_name="generate" # Give the endpoint a specific name
|
|
|
282 |
)
|
283 |
|
284 |
# Launch the interface with necessary parameters for Hugging Face Spaces
|
285 |
-
demo.
|
286 |
server_name="0.0.0.0", # Allow external access
|
287 |
server_port=7860, # Use the standard Gradio port
|
288 |
share=True, # Required for Hugging Face Spaces
|
289 |
show_error=True,
|
290 |
-
max_threads=1
|
291 |
)
|
|
|
262 |
processed = preprocess_image(image, bg_choice, fg_ratio, bg_color)
|
263 |
return gen_image(processed, seed_val, guidance, steps)
|
264 |
|
265 |
+
# Use concurrency_limit on the event listener instead of queue
|
266 |
text_button.click(
|
267 |
fn=generate,
|
268 |
inputs=[
|
|
|
279 |
xyz_output,
|
280 |
output_model
|
281 |
],
|
282 |
+
api_name="generate", # Give the endpoint a specific name
|
283 |
+
concurrency_limit=1 # Set concurrency limit directly on the event listener
|
284 |
)
|
285 |
|
286 |
# Launch the interface with necessary parameters for Hugging Face Spaces
|
287 |
+
demo.launch(
|
288 |
server_name="0.0.0.0", # Allow external access
|
289 |
server_port=7860, # Use the standard Gradio port
|
290 |
share=True, # Required for Hugging Face Spaces
|
291 |
show_error=True,
|
292 |
+
max_threads=1 # Control total number of workers
|
293 |
)
|