Spaces:
Runtime error
Runtime error
debugging inability to produce correct gif depending on parameters
Browse files- image_posterior.py +7 -3
image_posterior.py
CHANGED
|
@@ -54,6 +54,10 @@ def create_gif(explanation_blr, img_name, segments, image, n_images=20, n_max=5)
|
|
| 54 |
"""
|
| 55 |
draws = explanation_blr.draw_posterior_samples(n_images)
|
| 56 |
# Setup temporary directory to store paths in
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 58 |
paths = []
|
| 59 |
for i, d in tqdm(enumerate(draws)):
|
|
@@ -69,15 +73,15 @@ def create_gif(explanation_blr, img_name, segments, image, n_images=20, n_max=5)
|
|
| 69 |
# https://stackoverflow.com/questions/61716066/creating-an-animation-out-of-matplotlib-pngs
|
| 70 |
print(f"Saving gif to {img_name}_explanation.gif")
|
| 71 |
|
| 72 |
-
if(os.path.exists(f'
|
| 73 |
-
os.remove(f'
|
| 74 |
|
| 75 |
ims = [imageio.imread(f) for f in paths]
|
| 76 |
imageio.mimwrite(f'{img_name}_explanation.gif', ims)
|
| 77 |
|
| 78 |
html = (
|
| 79 |
"<div >"
|
| 80 |
-
f"<img src='
|
| 81 |
+ "</div>"
|
| 82 |
)
|
| 83 |
return html
|
|
|
|
| 54 |
"""
|
| 55 |
draws = explanation_blr.draw_posterior_samples(n_images)
|
| 56 |
# Setup temporary directory to store paths in
|
| 57 |
+
print("tempfile.tempdir:", tempfile.TemporaryDirectory)
|
| 58 |
+
if(os.path.exists(tempfile.TemporaryDirectory)):
|
| 59 |
+
os.remove(tempfile.TemporaryDirectory)
|
| 60 |
+
|
| 61 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 62 |
paths = []
|
| 63 |
for i, d in tqdm(enumerate(draws)):
|
|
|
|
| 73 |
# https://stackoverflow.com/questions/61716066/creating-an-animation-out-of-matplotlib-pngs
|
| 74 |
print(f"Saving gif to {img_name}_explanation.gif")
|
| 75 |
|
| 76 |
+
if(os.path.exists(f'file/{img_name}_explanation.gif')):
|
| 77 |
+
os.remove(f'file/{img_name}_explanation.gif')
|
| 78 |
|
| 79 |
ims = [imageio.imread(f) for f in paths]
|
| 80 |
imageio.mimwrite(f'{img_name}_explanation.gif', ims)
|
| 81 |
|
| 82 |
html = (
|
| 83 |
"<div >"
|
| 84 |
+
f"<img src='file/{img_name}_explanation.gif' alt='explanation gif'/>"
|
| 85 |
+ "</div>"
|
| 86 |
)
|
| 87 |
return html
|