Spaces:
Running
Running
Commit
·
bdeba65
1
Parent(s):
a0567be
init
Browse files
util.py
CHANGED
|
@@ -13,6 +13,7 @@ import gradio as gr
|
|
| 13 |
import boto3
|
| 14 |
import tempfile
|
| 15 |
import io
|
|
|
|
| 16 |
from botocore.client import Config
|
| 17 |
from PIL import Image
|
| 18 |
|
|
@@ -183,7 +184,9 @@ def upload_user_img_r2(clientIp, timeId, pil_image):
|
|
| 183 |
Returns:
|
| 184 |
str: Uploaded URL
|
| 185 |
"""
|
| 186 |
-
|
|
|
|
|
|
|
| 187 |
|
| 188 |
# Convert PIL Image to bytes
|
| 189 |
img_buffer = io.BytesIO()
|
|
@@ -270,7 +273,9 @@ def upload_mask_image_r2(client_ip, time_id, mask_image):
|
|
| 270 |
Returns:
|
| 271 |
str: Uploaded URL
|
| 272 |
"""
|
| 273 |
-
|
|
|
|
|
|
|
| 274 |
|
| 275 |
try:
|
| 276 |
# Convert mask image to bytes
|
|
|
|
| 13 |
import boto3
|
| 14 |
import tempfile
|
| 15 |
import io
|
| 16 |
+
import uuid
|
| 17 |
from botocore.client import Config
|
| 18 |
from PIL import Image
|
| 19 |
|
|
|
|
| 184 |
Returns:
|
| 185 |
str: Uploaded URL
|
| 186 |
"""
|
| 187 |
+
# Generate unique filename using UUID to prevent file conflicts in concurrent environment
|
| 188 |
+
unique_id = str(uuid.uuid4())
|
| 189 |
+
fileName = f"user_img_{unique_id}_{timeId}.jpg"
|
| 190 |
|
| 191 |
# Convert PIL Image to bytes
|
| 192 |
img_buffer = io.BytesIO()
|
|
|
|
| 273 |
Returns:
|
| 274 |
str: Uploaded URL
|
| 275 |
"""
|
| 276 |
+
# Generate unique filename using UUID to prevent file conflicts in concurrent environment
|
| 277 |
+
unique_id = str(uuid.uuid4())
|
| 278 |
+
file_name = f"mask_img_{unique_id}_{time_id}.png"
|
| 279 |
|
| 280 |
try:
|
| 281 |
# Convert mask image to bytes
|