vibs08 commited on
Commit
196feef
·
verified ·
1 Parent(s): 225fb1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -17
app.py CHANGED
@@ -274,24 +274,34 @@ def upload_file_to_s3(file_path, bucket_name, object_name):
274
 
275
  @app.post("/upload/")
276
  async def upload_image(file: UploadFile = File(...)):
277
- try:
278
- # Convert uploaded file to PIL Image
279
- image = Image.open(io.BytesIO(await file.read()))
280
-
281
- # Generate OBJ file in the temporary directory
282
- obj_file_path = step_1_generate_obj(image)
283
-
284
- # Generate a unique name for the S3 object
285
- timestamp = int(time.time())
286
- obj_name = f"object{timestamp}.obj"
287
-
288
- # Upload the OBJ file to S3
289
- s3_url = upload_file_to_s3(obj_file_path, 'framebucket3d', obj_name)
 
 
 
 
 
 
 
 
 
 
 
 
290
 
291
- return JSONResponse(content={"Output": s3_url})
292
-
293
- except Exception as e:
294
- raise HTTPException(status_code=500, detail=f"Error processing the image: {str(e)}")
295
 
296
  # Run FastAPI
297
  if __name__ == "__main__":
 
274
 
275
  @app.post("/upload/")
276
  async def upload_image(file: UploadFile = File(...)):
277
+ image_bytes = await file.read()
278
+ img_input = Image.open(BytesIO(image_bytes))
279
+ model_output = LitModel3D(
280
+ clear_color=[0.1, 0.1, 0.1, 0], # can adjust background color for better contrast
281
+ label="3D Model Visualization",
282
+ scale=1.0,
283
+ tonemapping="aces", # can use aces tonemapping for more realistic lighting
284
+ exposure=1.0, # can adjust exposure to control brightness
285
+ contrast=1.1, # can slightly increase contrast for better depth
286
+ camera_position=(0, 0, 2), # will set initial camera position to center the model
287
+ zoom_speed=0.5, # will adjust zoom speed for better control
288
+ pan_speed=0.5, # will adjust pan speed for better control
289
+ interactive=True # this allow users to interact with the model
290
+ )
291
+
292
+ obj_file_output, model_output = step_1_generate_obj(img_input)
293
+
294
+ timestamp = datetime.datetime.now().astimezone().strftime('%Y%m%d%H%M%S%f%z')
295
+ object_name = f'object_{timestamp}.obj'
296
+
297
+ if upload_file_to_s3(obj_file_output, 'framebucket3d',object_name):
298
+
299
+ return {
300
+ "obj_path": f"https://framebucket3d.s3.amazonaws.com/{object_name}"
301
+ }
302
 
303
+
304
+
 
 
305
 
306
  # Run FastAPI
307
  if __name__ == "__main__":