Update apps/gradio_app/examples.py
Browse files- apps/gradio_app/examples.py +18 -25
apps/gradio_app/examples.py
CHANGED
@@ -5,37 +5,30 @@ import gradio as gr
|
|
5 |
|
6 |
def load_examples():
|
7 |
examples = []
|
8 |
-
examples_base_path = os.path.join(
|
9 |
|
10 |
-
for folder in
|
11 |
folder_path = os.path.join(examples_base_path, folder)
|
12 |
config_path = os.path.join(folder_path, "config.json")
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
Image.open(output_image_path).close()
|
29 |
-
examples.append([input_image_path, output_image_path, outer_scale])
|
30 |
-
except (json.JSONDecodeError, OSError) as e:
|
31 |
-
print(f"Error loading example in folder {folder}: {e}")
|
32 |
-
continue
|
33 |
|
34 |
return examples
|
35 |
|
36 |
def select_example(evt: gr.SelectData, examples_data):
|
37 |
-
if not examples_data:
|
38 |
-
return None, 2, None, "No examples available"
|
39 |
example_index = evt.index
|
40 |
-
|
41 |
-
return
|
|
|
5 |
|
6 |
def load_examples():
|
7 |
examples = []
|
8 |
+
examples_base_path = os.path.join("apps", "assets", "examples", "Real-ESRGAN-Anime-finetuning")
|
9 |
|
10 |
+
for folder in ["1", "2", "3", "4"]:
|
11 |
folder_path = os.path.join(examples_base_path, folder)
|
12 |
config_path = os.path.join(folder_path, "config.json")
|
13 |
|
14 |
+
if os.path.exists(config_path):
|
15 |
+
with open(config_path, 'r') as f:
|
16 |
+
config = json.load(f)
|
17 |
+
input_filename = config.get("input_file", "input.jpg")
|
18 |
+
output_filename = config.get("output_file", "output.jpg")
|
19 |
+
outer_scale = config.get("outer_scale", 4)
|
20 |
+
|
21 |
+
input_image_path = os.path.join(folder_path, input_filename)
|
22 |
+
output_image_path = os.path.join(folder_path, output_filename)
|
23 |
+
|
24 |
+
if os.path.exists(input_image_path) and os.path.exists(output_image_path):
|
25 |
+
input_image_data = Image.open(input_image_path)
|
26 |
+
output_image_data = Image.open(output_image_path)
|
27 |
+
examples.append([input_image_data, output_image_data, outer_scale])
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
return examples
|
30 |
|
31 |
def select_example(evt: gr.SelectData, examples_data):
|
|
|
|
|
32 |
example_index = evt.index
|
33 |
+
input_image_data, output_image_data, outer_scale = examples_data[example_index]
|
34 |
+
return input_image_data, outer_scale, output_image_data, f"Loaded example with Outer Scale: {outer_scale}"
|