Spaces:
Runtime error
Runtime error
moved images to data folder, cleaned up code
Browse files- .htaccess +0 -3
- app.py +9 -9
- bird.jpg β data/bird.jpg +0 -0
- diego.png β data/diego.png +0 -0
- french_bulldog.jpg β data/french_bulldog.jpg +0 -0
- hockey.jpg β data/hockey.jpg +0 -0
- pepper.jpeg β data/pepper.jpeg +0 -0
- image_posterior.py +5 -5
.htaccess
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
AddType video/ogg .ogv
|
2 |
-
AddType video/mp4 .mp4
|
3 |
-
AddType video/webm .webm
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -30,10 +30,10 @@ def get_image_data(inp_image):
|
|
30 |
return image, model_and_data
|
31 |
|
32 |
|
33 |
-
def segmentation_generation(
|
34 |
-
print("Inputs Received:",
|
35 |
|
36 |
-
image, model_and_data = get_image_data(
|
37 |
|
38 |
# Unpack datax
|
39 |
xtest = model_and_data["xtest"]
|
@@ -76,7 +76,7 @@ def segmentation_generation(image_name, c_width, n_top, n_gif_imgs):
|
|
76 |
l2=False)
|
77 |
|
78 |
# Create the gif of the explanation
|
79 |
-
return create_gif(rout['blr'],
|
80 |
|
81 |
if __name__ == "__main__":
|
82 |
inp = gr.inputs.Image(label="Input Image (Or select an example)", type="pil")
|
@@ -91,10 +91,10 @@ if __name__ == "__main__":
|
|
91 |
gr.inputs.Slider(minimum=10, maximum=100, step=1, default=30, label="n_gif_images", optional=False),
|
92 |
],
|
93 |
outputs=out,
|
94 |
-
examples=[["./diego.png", 0.01, 7, 50],
|
95 |
-
["./french_bulldog.jpg", 0.01, 5, 50],
|
96 |
-
["./pepper.jpeg", 0.01, 5, 50],
|
97 |
-
["./bird.jpg", 0.01, 5, 50],
|
98 |
-
["./hockey.jpg", 0.01, 5, 50]]
|
99 |
)
|
100 |
iface.launch(enable_queue=True)
|
|
|
30 |
return image, model_and_data
|
31 |
|
32 |
|
33 |
+
def segmentation_generation(input_image, c_width, n_top, n_gif_imgs):
|
34 |
+
print("Inputs Received:", input_image, c_width, n_top, n_gif_imgs)
|
35 |
|
36 |
+
image, model_and_data = get_image_data(input_image)
|
37 |
|
38 |
# Unpack datax
|
39 |
xtest = model_and_data["xtest"]
|
|
|
76 |
l2=False)
|
77 |
|
78 |
# Create the gif of the explanation
|
79 |
+
return create_gif(rout['blr'], input_image, segments, instance, prediction[0], n_gif_imgs, n_top)
|
80 |
|
81 |
if __name__ == "__main__":
|
82 |
inp = gr.inputs.Image(label="Input Image (Or select an example)", type="pil")
|
|
|
91 |
gr.inputs.Slider(minimum=10, maximum=100, step=1, default=30, label="n_gif_images", optional=False),
|
92 |
],
|
93 |
outputs=out,
|
94 |
+
examples=[["./data/diego.png", 0.01, 7, 50],
|
95 |
+
["./data/french_bulldog.jpg", 0.01, 5, 50],
|
96 |
+
["./data/pepper.jpeg", 0.01, 5, 50],
|
97 |
+
["./data/bird.jpg", 0.01, 5, 50],
|
98 |
+
["./data/hockey.jpg", 0.01, 5, 50]]
|
99 |
)
|
100 |
iface.launch(enable_queue=True)
|
bird.jpg β data/bird.jpg
RENAMED
File without changes
|
diego.png β data/diego.png
RENAMED
File without changes
|
french_bulldog.jpg β data/french_bulldog.jpg
RENAMED
File without changes
|
hockey.jpg β data/hockey.jpg
RENAMED
File without changes
|
pepper.jpeg β data/pepper.jpeg
RENAMED
File without changes
|
image_posterior.py
CHANGED
@@ -82,17 +82,17 @@ def create_gif(explanation_blr, img_name, segments, image, prediction, n_images=
|
|
82 |
|
83 |
# Save to gif
|
84 |
# https://stackoverflow.com/questions/61716066/creating-an-animation-out-of-matplotlib-pngs
|
85 |
-
print(f"Saving gif to {
|
86 |
|
87 |
-
if(os.path.exists(f'{
|
88 |
-
os.remove(f'{
|
89 |
|
90 |
ims = [imageio.imread(f) for f in paths]
|
91 |
-
imageio.mimwrite(f'{
|
92 |
|
93 |
html = (
|
94 |
"<div>"
|
95 |
-
+ f"<img src='file/{
|
96 |
+ "</div>"
|
97 |
)
|
98 |
|
|
|
82 |
|
83 |
# Save to gif
|
84 |
# https://stackoverflow.com/questions/61716066/creating-an-animation-out-of-matplotlib-pngs
|
85 |
+
print(f"Saving gif to {str(prediction)}_explanation.gif")
|
86 |
|
87 |
+
if(os.path.exists(f'{str(prediction)}_explanation.gif')):
|
88 |
+
os.remove(f'{str(prediction)}_explanation.gif')
|
89 |
|
90 |
ims = [imageio.imread(f) for f in paths]
|
91 |
+
imageio.mimwrite(f'{str(prediction)}_explanation.gif', ims)
|
92 |
|
93 |
html = (
|
94 |
"<div>"
|
95 |
+
+ f"<img src='file/{str(prediction)}_explanation.gif' alt='explanation gif'/>"
|
96 |
+ "</div>"
|
97 |
)
|
98 |
|