Spaces:
Runtime error
Runtime error
Update inference.py
Browse files- inference.py +13 -13
inference.py
CHANGED
|
@@ -82,16 +82,16 @@ def generate_image_from_text_with_persistent_storage(caption, batch_size=4):
|
|
| 82 |
# generate the images
|
| 83 |
generated_images = generator(noise, sent_emb, eval=True).float()
|
| 84 |
|
| 85 |
-
# Create a
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
| 82 |
# generate the images
|
| 83 |
generated_images = generator(noise, sent_emb, eval=True).float()
|
| 84 |
|
| 85 |
+
# Create a permanent directory if it doesn't exist
|
| 86 |
+
permanent_dir = "generated_images"
|
| 87 |
+
if not os.path.exists(permanent_dir):
|
| 88 |
+
os.makedirs(permanent_dir)
|
| 89 |
+
|
| 90 |
+
image_paths = []
|
| 91 |
+
for idx, image_tensor in enumerate(generated_images.unbind(0)):
|
| 92 |
+
# Save the image tensor to a permanent file
|
| 93 |
+
image_path = os.path.join(permanent_dir, f"image_{idx}.png")
|
| 94 |
+
torchvision.utils.save_image(image_tensor.data, image_path, value_range=(-1, 1), normalize=True)
|
| 95 |
+
image_paths.append(image_path)
|
| 96 |
+
|
| 97 |
+
return image_paths
|