Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import uuid
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def generate_id():
|
| 6 |
+
return str(uuid.uuid4())
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def ensure_dir(path):
|
| 10 |
+
if not os.path.exists(path):
|
| 11 |
+
os.makedirs(path)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def save_image(image, folder="outputs"):
|
| 15 |
+
ensure_dir(folder)
|
| 16 |
+
|
| 17 |
+
file_path = os.path.join(folder, f"{generate_id()}.png")
|
| 18 |
+
|
| 19 |
+
image.save(file_path)
|
| 20 |
+
|
| 21 |
+
return file_path
|