Update apps/gradio_app/examples.py
Browse files- apps/gradio_app/examples.py +40 -40
apps/gradio_app/examples.py
CHANGED
@@ -1,41 +1,41 @@
|
|
1 |
-
import os
|
2 |
-
import json
|
3 |
-
from PIL import Image
|
4 |
-
import gradio as gr
|
5 |
-
|
6 |
-
def load_examples():
|
7 |
-
examples = []
|
8 |
-
examples_base_path = os.path.join(os.path.dirname(__file__), "..", "assets", "examples", "Real-ESRGAN-Anime-finetuning")
|
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 |
-
try:
|
15 |
-
if os.path.exists(config_path):
|
16 |
-
with open(config_path, 'r') as f:
|
17 |
-
config = json.load(f)
|
18 |
-
input_filename = config.get("input_file", "input.jpg")
|
19 |
-
output_filename = config.get("output_file", "output.jpg")
|
20 |
-
outer_scale = config.get("outer_scale", 4)
|
21 |
-
|
22 |
-
input_image_path = os.path.join(folder_path, input_filename)
|
23 |
-
output_image_path = os.path.join(folder_path, output_filename)
|
24 |
-
|
25 |
-
if os.path.exists(input_image_path) and os.path.exists(output_image_path):
|
26 |
-
# Verify images can be opened
|
27 |
-
Image.open(input_image_path).close()
|
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 |
-
input_image_path, output_image_path, outer_scale = examples_data[example_index]
|
41 |
return input_image_path, outer_scale, output_image_path, f"Loaded example with Outer Scale: {outer_scale}"
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from PIL import Image
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
def load_examples():
|
7 |
+
examples = []
|
8 |
+
examples_base_path = os.path.join(os.path.dirname(__file__), "..", "assets", "examples", "Real-ESRGAN-Anime-finetuning")
|
9 |
+
|
10 |
+
for folder in os.listdir(examples_base_path):
|
11 |
+
folder_path = os.path.join(examples_base_path, folder)
|
12 |
+
config_path = os.path.join(folder_path, "config.json")
|
13 |
+
|
14 |
+
try:
|
15 |
+
if os.path.exists(config_path):
|
16 |
+
with open(config_path, 'r') as f:
|
17 |
+
config = json.load(f)
|
18 |
+
input_filename = config.get("input_file", "input.jpg")
|
19 |
+
output_filename = config.get("output_file", "output.jpg")
|
20 |
+
outer_scale = config.get("outer_scale", 4)
|
21 |
+
|
22 |
+
input_image_path = os.path.join(folder_path, input_filename)
|
23 |
+
output_image_path = os.path.join(folder_path, output_filename)
|
24 |
+
|
25 |
+
if os.path.exists(input_image_path) and os.path.exists(output_image_path):
|
26 |
+
# Verify images can be opened
|
27 |
+
Image.open(input_image_path).close()
|
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 |
+
input_image_path, output_image_path, outer_scale = examples_data[example_index]
|
41 |
return input_image_path, outer_scale, output_image_path, f"Loaded example with Outer Scale: {outer_scale}"
|