Lisandro commited on
Commit
8fa2633
·
1 Parent(s): 0fa35ac

feat: Enable lazy loading of examples in app.py

Browse files

This commit enables lazy loading of examples in the `app.py` file. Previously, the `gr.Examples` block was commented out, but now it has been uncommented to allow for the lazy loading of examples. This improves the performance of the application by only loading examples when needed, reducing the initial load time and optimizing resource usage.

Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -17,16 +17,14 @@ def infer(selected_space, prompt, seed=42, randomize_seed=False, width=1024, hei
17
  global job
18
  global client
19
 
20
- # Asegúrate de que selected_space_index esté inicializado antes de este bloque de código
21
- max_attempts = len(flux_1_schell_spaces)
22
- attempts = 0
23
-
24
- try:
25
- client = Client(selected_space)
26
- print(f"Loaded custom model from {selected_space}")
27
- except ValueError as e:
28
- print(f"Failed to load custom model from {selected_space}: {e}")
29
- raise gr.Error("Failed to load client after trying all spaces.")
30
 
31
  try:
32
  job = client.submit(
@@ -40,6 +38,7 @@ def infer(selected_space, prompt, seed=42, randomize_seed=False, width=1024, hei
40
  )
41
  result = job.result()
42
  except ValueError as e:
 
43
  raise gr.Error(e)
44
 
45
  return result
 
17
  global job
18
  global client
19
 
20
+ if client is None:
21
+ try:
22
+ client = Client(selected_space)
23
+ print(f"Loaded custom model from {selected_space}")
24
+ except ValueError as e:
25
+ client = None
26
+ print(f"Failed to load custom model from {selected_space}: {e}")
27
+ raise gr.Error("Failed to load client after trying all spaces.")
 
 
28
 
29
  try:
30
  job = client.submit(
 
38
  )
39
  result = job.result()
40
  except ValueError as e:
41
+ client = None
42
  raise gr.Error(e)
43
 
44
  return result