Update app.py
Browse files
app.py
CHANGED
@@ -29,6 +29,8 @@ import uuid
|
|
29 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
30 |
from fastapi.responses import JSONResponse
|
31 |
import datetime
|
|
|
|
|
32 |
|
33 |
app = FastAPI()
|
34 |
|
@@ -274,16 +276,18 @@ async def upload_image(file: UploadFile = File(...)):
|
|
274 |
# Convert uploaded file to PIL Image
|
275 |
image = Image.open(io.BytesIO(await file.read()))
|
276 |
|
277 |
-
#
|
278 |
-
|
|
|
|
|
279 |
|
280 |
-
|
281 |
-
|
282 |
|
283 |
-
|
284 |
-
|
285 |
|
286 |
-
|
287 |
|
288 |
except Exception as e:
|
289 |
raise HTTPException(status_code=500, detail=f"Error processing the image: {str(e)}")
|
|
|
29 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
30 |
from fastapi.responses import JSONResponse
|
31 |
import datetime
|
32 |
+
import tempfile
|
33 |
+
|
34 |
|
35 |
app = FastAPI()
|
36 |
|
|
|
276 |
# Convert uploaded file to PIL Image
|
277 |
image = Image.open(io.BytesIO(await file.read()))
|
278 |
|
279 |
+
# Create a temporary directory to store the OBJ file
|
280 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
281 |
+
# Generate OBJ file in the temporary directory
|
282 |
+
obj_file_path = step_1_generate_obj(image, temp_dir)
|
283 |
|
284 |
+
# Generate a unique name for the S3 object
|
285 |
+
obj_name = f"{uuid.uuid4()}.obj"
|
286 |
|
287 |
+
# Upload the OBJ file to S3
|
288 |
+
s3_url = save_file_to_s3(obj_file_path, 'framebucket3d', obj_name)
|
289 |
|
290 |
+
return JSONResponse(content={"Output": s3_url})
|
291 |
|
292 |
except Exception as e:
|
293 |
raise HTTPException(status_code=500, detail=f"Error processing the image: {str(e)}")
|