Spaces:
Running
on
Zero
Running
on
Zero
jadechoghari
commited on
Commit
•
c6dfc2e
1
Parent(s):
25f002c
Update app.py
Browse files
app.py
CHANGED
@@ -40,9 +40,22 @@ def load_cached_example_outputs(example_index: int) -> Tuple[Union[str, None], s
|
|
40 |
raise FileNotFoundError(f"Cached outputs not found for example {example_index}")
|
41 |
|
42 |
# to handle the example click
|
43 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
return load_cached_example_outputs(example_index)
|
45 |
|
|
|
46 |
# # to handle the example click, it now accepts arbitrary arguments
|
47 |
# def on_example_click(*args, **kwargs):
|
48 |
# return load_cached_example_outputs(1) # Always load example 1 for now
|
@@ -118,11 +131,11 @@ with gr.Blocks(css=css) as demo:
|
|
118 |
|
119 |
# Example inputs, the last two are videos
|
120 |
examples = [
|
121 |
-
["
|
122 |
-
["
|
123 |
-
["
|
124 |
-
["
|
125 |
-
["
|
126 |
]
|
127 |
|
128 |
# Function to dynamically switch output visibility based on file type
|
@@ -135,10 +148,11 @@ with gr.Blocks(css=css) as demo:
|
|
135 |
|
136 |
# Add the examples to Gradio
|
137 |
gr.Examples(
|
138 |
-
examples=
|
139 |
-
inputs=[
|
140 |
-
outputs=[processed_image,
|
141 |
-
|
|
|
142 |
)
|
143 |
|
144 |
gr.on(
|
|
|
40 |
raise FileNotFoundError(f"Cached outputs not found for example {example_index}")
|
41 |
|
42 |
# to handle the example click
|
43 |
+
def load_cached_example_outputs(example_index: int) -> Tuple[str, str]:
|
44 |
+
cached_dir = os.path.join(CACHE_DIR, str(example_index)) # use the example index to find the directory
|
45 |
+
cached_image_path = os.path.join(cached_dir, "processed_image.png")
|
46 |
+
cached_audio_path = os.path.join(cached_dir, "audio.wav")
|
47 |
+
|
48 |
+
# Ensure cached files exist
|
49 |
+
if os.path.exists(cached_image_path) and os.path.exists(cached_audio_path):
|
50 |
+
return cached_image_path, cached_audio_path
|
51 |
+
else:
|
52 |
+
raise FileNotFoundError(f"Cached outputs not found for example {example_index}")
|
53 |
+
|
54 |
+
# Function to handle the example click, it now accepts arbitrary arguments and returns the appropriate cached outputs
|
55 |
+
def on_example_click(*args, example_index=1, **kwargs):
|
56 |
return load_cached_example_outputs(example_index)
|
57 |
|
58 |
+
|
59 |
# # to handle the example click, it now accepts arbitrary arguments
|
60 |
# def on_example_click(*args, **kwargs):
|
61 |
# return load_cached_example_outputs(1) # Always load example 1 for now
|
|
|
131 |
|
132 |
# Example inputs, the last two are videos
|
133 |
examples = [
|
134 |
+
["gradio_cached_examples/1/processed_image.png", 3, "Example 1", 500],
|
135 |
+
["gradio_cached_examples/2/processed_image.png", 3, "Example 2", 500],
|
136 |
+
["gradio_cached_examples/3/processed_image.png", 3, "Example 3", 500],
|
137 |
+
# ["gradio_cached_examples/4/processed_image.png", 3, "Example 4", 500],
|
138 |
+
# ["gradio_cached_examples/4/processed_image.png", 3, "Example 5", 500]
|
139 |
]
|
140 |
|
141 |
# Function to dynamically switch output visibility based on file type
|
|
|
148 |
|
149 |
# Add the examples to Gradio
|
150 |
gr.Examples(
|
151 |
+
examples=example_inputs,
|
152 |
+
inputs=[image, num_audios, prompt, steps],
|
153 |
+
outputs=[processed_image, generated_audio],
|
154 |
+
cache_examples=True,
|
155 |
+
fn=lambda *args, **kwargs: on_example_click(example_index=args[0][0]), # Select the correct example based on the index
|
156 |
)
|
157 |
|
158 |
gr.on(
|