Spaces:
Runtime error
Runtime error
feat: Enable lazy loading of examples in app.py
Browse filesThis 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.
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 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
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
|