Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -26,19 +26,18 @@ model.setup()
|
|
26 |
CACHE_DIR = "gradio_cached_examples"
|
27 |
|
28 |
#for local cache
|
29 |
-
def load_cached_example_outputs(example_index: int) -> Tuple[
|
30 |
-
cached_dir = os.path.join(CACHE_DIR, str(example_index))
|
31 |
cached_image_path = os.path.join(cached_dir, "processed_image.png")
|
32 |
cached_audio_path = os.path.join(cached_dir, "audio.wav")
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
return cached_video_path, cached_audio_path # Return video output
|
37 |
-
elif os.path.exists(cached_image_path) and os.path.exists(cached_audio_path):
|
38 |
-
return cached_image_path, cached_audio_path # Return image output
|
39 |
else:
|
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
|
@@ -138,21 +137,16 @@ with gr.Blocks(css=css) as demo:
|
|
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
|
142 |
def handle_example_click(example):
|
143 |
-
output, audio = on_example_click(int(example[0][-
|
144 |
-
|
145 |
-
return None, output, audio # Show video and hide image
|
146 |
-
else:
|
147 |
-
return output, None, audio # Show image and hide video
|
148 |
|
149 |
# Add the examples to Gradio
|
150 |
gr.Examples(
|
151 |
examples=examples,
|
152 |
inputs=[image, num_audios, prompt, steps],
|
153 |
outputs=[processed_image, generated_audio],
|
154 |
-
|
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(
|
|
|
26 |
CACHE_DIR = "gradio_cached_examples"
|
27 |
|
28 |
#for local cache
|
29 |
+
def load_cached_example_outputs(example_index: int) -> Tuple[str, str]:
|
30 |
+
cached_dir = os.path.join(CACHE_DIR, str(example_index))
|
31 |
cached_image_path = os.path.join(cached_dir, "processed_image.png")
|
32 |
cached_audio_path = os.path.join(cached_dir, "audio.wav")
|
33 |
+
|
34 |
+
if os.path.exists(cached_image_path) and os.path.exists(cached_audio_path):
|
35 |
+
return cached_image_path, cached_audio_path
|
|
|
|
|
|
|
36 |
else:
|
37 |
raise FileNotFoundError(f"Cached outputs not found for example {example_index}")
|
38 |
|
39 |
+
|
40 |
+
|
41 |
# to handle the example click
|
42 |
def load_cached_example_outputs(example_index: int) -> Tuple[str, str]:
|
43 |
cached_dir = os.path.join(CACHE_DIR, str(example_index)) # use the example index to find the directory
|
|
|
137 |
# ["gradio_cached_examples/4/processed_image.png", 3, "Example 5", 500]
|
138 |
]
|
139 |
|
|
|
140 |
def handle_example_click(example):
|
141 |
+
output, audio = on_example_click(int(example[0].split('/')[-2])) # Extract index from path
|
142 |
+
return output, audio
|
|
|
|
|
|
|
143 |
|
144 |
# Add the examples to Gradio
|
145 |
gr.Examples(
|
146 |
examples=examples,
|
147 |
inputs=[image, num_audios, prompt, steps],
|
148 |
outputs=[processed_image, generated_audio],
|
149 |
+
fn=handle_example_click
|
|
|
150 |
)
|
151 |
|
152 |
gr.on(
|