Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ import os
|
|
8 |
from PIL import Image
|
9 |
import torchvision.transforms as transforms
|
10 |
|
|
|
|
|
11 |
# Pobierz model i config
|
12 |
repo_id = "Kiwinicki/sat2map-generator"
|
13 |
generator_path = hf_hub_download(repo_id=repo_id, filename="generator.pth")
|
@@ -51,11 +53,72 @@ def process_image(image):
|
|
51 |
|
52 |
return output_image
|
53 |
|
54 |
-
iface = gr.Interface(
|
55 |
-
fn=process_image,
|
56 |
-
inputs=gr.Image(type="pil"),
|
57 |
-
outputs="image",
|
58 |
-
title="Satellite to Map Generator"
|
59 |
-
)
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
from PIL import Image
|
9 |
import torchvision.transforms as transforms
|
10 |
|
11 |
+
photos_folder = "Photos"
|
12 |
+
|
13 |
# Pobierz model i config
|
14 |
repo_id = "Kiwinicki/sat2map-generator"
|
15 |
generator_path = hf_hub_download(repo_id=repo_id, filename="generator.pth")
|
|
|
53 |
|
54 |
return output_image
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
def load_images_from_folder(folder):
|
58 |
+
images = []
|
59 |
+
for filename in os.listdir(folder):
|
60 |
+
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
|
61 |
+
img_path = os.path.join(folder, filename)
|
62 |
+
img = Image.open(img_path)
|
63 |
+
images.append((img, filename))
|
64 |
+
return images
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
def load_image_from_gallery(images, index):
|
69 |
+
if images and 0 <= index < len(images):
|
70 |
+
image = images[index]
|
71 |
+
if isinstance(image, tuple):
|
72 |
+
image = image[0]
|
73 |
+
return image
|
74 |
+
return None
|
75 |
+
|
76 |
+
|
77 |
+
def gallery_click_event(images, evt: gr.SelectData):
|
78 |
+
index = evt.index
|
79 |
+
selected_img = load_image_from_gallery(images, index)
|
80 |
+
return selected_img
|
81 |
+
|
82 |
+
|
83 |
+
def clear_image():
|
84 |
+
return None
|
85 |
+
|
86 |
+
|
87 |
+
def app():
|
88 |
+
images = load_images_from_folder(photos_folder)
|
89 |
+
|
90 |
+
with gr.Blocks(css=".container { background-color: white; }") as demo:
|
91 |
+
with gr.Row():
|
92 |
+
with gr.Column():
|
93 |
+
selected_image = gr.Image(label="Input Image", type="pil")
|
94 |
+
clear_button = gr.Button("Clear")
|
95 |
+
|
96 |
+
with gr.Column():
|
97 |
+
image_gallery = gr.Gallery(label="Image Gallery", elem_id="gallery", type="pil", value=[img for img, _ in images])
|
98 |
+
|
99 |
+
with gr.Column():
|
100 |
+
result_image = gr.Image(label="Result Image", type="pil")
|
101 |
+
|
102 |
+
image_gallery.select(
|
103 |
+
fn=gallery_click_event,
|
104 |
+
inputs=image_gallery,
|
105 |
+
outputs=selected_image
|
106 |
+
)
|
107 |
+
|
108 |
+
selected_image.change(
|
109 |
+
fn=process_image,
|
110 |
+
inputs=selected_image,
|
111 |
+
outputs=result_image
|
112 |
+
)
|
113 |
+
|
114 |
+
clear_button.click(
|
115 |
+
fn=clear_image,
|
116 |
+
inputs=None,
|
117 |
+
outputs=selected_image
|
118 |
+
)
|
119 |
+
|
120 |
+
demo.launch()
|
121 |
+
|
122 |
+
|
123 |
+
if __name__ == "__main__":
|
124 |
+
app()
|