Spaces:
Runtime error
Runtime error
using html to embed video into demo
Browse files- app.py +13 -6
- image_posterior.py +16 -1
app.py
CHANGED
@@ -21,6 +21,8 @@ parser.add_argument("--save_loc", type=str, required=True)
|
|
21 |
parser.add_argument("--n_top_segs", type=int, default=5)
|
22 |
parser.add_argument("--n_gif_images", type=int, default=20)
|
23 |
|
|
|
|
|
24 |
IMAGE_NAME = "imagenet_diego"
|
25 |
BLENHEIM_SPANIEL_CLASS = 156
|
26 |
|
@@ -76,18 +78,23 @@ def segmentation_generation(image_name, c_width, n_top, n_gif_imgs):
|
|
76 |
|
77 |
def image_mod(image):
|
78 |
return image.rotate(45)
|
79 |
-
|
80 |
-
|
81 |
if __name__ == "__main__":
|
|
|
82 |
inp = gr.inputs.Image(label="Input Image", type="pil")
|
83 |
-
out = gr.outputs.
|
84 |
|
85 |
iface = gr.Interface(
|
86 |
segmentation_generation,
|
87 |
[
|
88 |
inp,
|
89 |
-
gr.inputs.Slider(minimum=0.
|
90 |
gr.inputs.Slider(minimum=1, maximum=10, step=1, default=5, label="n_top_segs", optional=False),
|
91 |
gr.inputs.Slider(minimum=10, maximum=50, step=1, default=20, label="n_gif_images", optional=False),
|
92 |
-
],
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
21 |
parser.add_argument("--n_top_segs", type=int, default=5)
|
22 |
parser.add_argument("--n_gif_images", type=int, default=20)
|
23 |
|
24 |
+
# app = flask.Flask(__name__, template_folder="./")
|
25 |
+
|
26 |
IMAGE_NAME = "imagenet_diego"
|
27 |
BLENHEIM_SPANIEL_CLASS = 156
|
28 |
|
|
|
78 |
|
79 |
def image_mod(image):
|
80 |
return image.rotate(45)
|
81 |
+
|
|
|
82 |
if __name__ == "__main__":
|
83 |
+
|
84 |
inp = gr.inputs.Image(label="Input Image", type="pil")
|
85 |
+
out = gr.outputs.HTML(label="Output Video")
|
86 |
|
87 |
iface = gr.Interface(
|
88 |
segmentation_generation,
|
89 |
[
|
90 |
inp,
|
91 |
+
gr.inputs.Slider(minimum=0.01, maximum=0.8, step=0.001, default=0.1, label="cred_width", optional=False),
|
92 |
gr.inputs.Slider(minimum=1, maximum=10, step=1, default=5, label="n_top_segs", optional=False),
|
93 |
gr.inputs.Slider(minimum=10, maximum=50, step=1, default=20, label="n_gif_images", optional=False),
|
94 |
+
],
|
95 |
+
outputs=out,
|
96 |
+
examples=[["./imagenet_diego.png", 0.05, 7, 50]]
|
97 |
+
)
|
98 |
+
iface.launch()
|
99 |
+
|
100 |
+
# app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
image_posterior.py
CHANGED
@@ -68,6 +68,21 @@ def create_gif(explanation_blr, segments, image, n_images=20, n_max=5):
|
|
68 |
# Save to gif
|
69 |
# https://stackoverflow.com/questions/61716066/creating-an-animation-out-of-matplotlib-pngs
|
70 |
# print(f"Saving gif to {save_loc}")
|
|
|
71 |
ims = [imageio.imread(f) for f in paths]
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
|
|
68 |
# Save to gif
|
69 |
# https://stackoverflow.com/questions/61716066/creating-an-animation-out-of-matplotlib-pngs
|
70 |
# print(f"Saving gif to {save_loc}")
|
71 |
+
|
72 |
ims = [imageio.imread(f) for f in paths]
|
73 |
+
writer = imageio.get_writer('C:/Users/pineapples/Documents/research/Modeling-Uncertainty-Local-Explainability/Modeling-Uncertainty-in-Explainability-Demo/test.mp4', fps = n_images)
|
74 |
+
for im in ims:
|
75 |
+
writer.append_data(im)
|
76 |
+
writer.close()
|
77 |
+
|
78 |
+
|
79 |
+
html = '''
|
80 |
+
<div style='max-width:100%; max-height:360px; overflow:auto'>
|
81 |
+
<video width="320" height="240" autoplay>
|
82 |
+
<source src="/build/videos/arcnet.io(7-sec).mp4" type=video/mp4>
|
83 |
+
</video>
|
84 |
+
</div>
|
85 |
+
)'''
|
86 |
+
return html
|
87 |
+
# return imageio.mimwrite(imageio.RETURN_BYTES, ims)
|
88 |
|