jadechoghari commited on
Commit
b7fdbe0
·
verified ·
1 Parent(s): a1a5a34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -27,18 +27,23 @@ 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)) # Use the example index to find the directory
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
- print(f"Looking for cached image at: {cached_image_path}")
35
- print(f"Looking for cached audio at: {cached_audio_path}")
36
-
37
- # Ensure cached files exist
38
- if os.path.exists(cached_image_path) and os.path.exists(cached_audio_path):
39
- return cached_image_path, cached_audio_path
40
- else:
41
- raise FileNotFoundError(f"Cached outputs not found for example {example_index}")
 
 
 
 
 
42
 
43
  # Function to handle the example click, it now accepts arbitrary arguments and returns the appropriate cached outputs
44
  def on_example_click(*args, example_index=1, **kwargs):
 
27
 
28
  #for local cache
29
  def load_cached_example_outputs(example_index: int) -> Tuple[str, str]:
30
+ # Search for any folder that contains the example index in its name
31
+ for root, dirs, files in os.walk(CACHE_DIR):
32
+ for dir_name in dirs:
33
+ if dir_name.endswith(str(example_index)): # Search for folder ending with the example index
34
+ cached_dir = os.path.join(root, dir_name)
35
+ cached_image_path = os.path.join(cached_dir, "processed_image.png")
36
+ cached_audio_path = os.path.join(cached_dir, "audio.wav")
37
+
38
+ # Debugging: Print the paths being checked
39
+ print(f"Looking for cached image at: {cached_image_path}")
40
+ print(f"Looking for cached audio at: {cached_audio_path}")
41
+
42
+ # Check if the cached files exist
43
+ if os.path.exists(cached_image_path) and os.path.exists(cached_audio_path):
44
+ return cached_image_path, cached_audio_path
45
+
46
+ raise FileNotFoundError(f"Cached outputs not found for example {example_index}")
47
 
48
  # Function to handle the example click, it now accepts arbitrary arguments and returns the appropriate cached outputs
49
  def on_example_click(*args, example_index=1, **kwargs):