Inigozr commited on
Commit
bde6aa6
·
1 Parent(s): d89619d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -20
app.py CHANGED
@@ -60,6 +60,8 @@ async def detect_yolo(request: Request, url: str = Form(...)
60
 
61
  except Exception as e:
62
  raise HTTPException(status_code=500, detail=f"Error processing image: {str(e)}")
 
 
63
  @app.get("/test")
64
  async def read_root():
65
  return {"message": "TEST"}
@@ -67,24 +69,4 @@ async def read_root():
67
 
68
  @app.get("/")
69
  async def read_root():
70
- # Download image content from URL
71
- image_url = "https://s1.eestatic.com/2018/04/10/actualidad/actualidad_298735505_130172549_1000x500.jpg"
72
- response = requests.get(image_url)
73
- response.raise_for_status()
74
-
75
- # Open the image using PIL
76
- image = Image.open(io.BytesIO(response.content))
77
- # Perform YOLO prediction
78
- predictions = predict_yolo(image_url)
79
-
80
- # Draw bounding boxes on the image
81
- image_np = np.array(image)
82
- image_with_boxes = draw_boxes(image_np, predictions)
83
-
84
- # Save the image with bounding boxes
85
- image_with_boxes_path = f"/tmp/{file.filename.split('.')[0]}_with_boxes.jpg"
86
- cv2.imwrite(image_with_boxes_path, cv2.cvtColor(image_with_boxes, cv2.COLOR_RGB2BGR))
87
-
88
- # Render the HTML with the image and bounding boxes
89
- return templates.TemplateResponse("prediction.html", {"request": file, "image_path": image_with_boxes_path})
90
  return {"message": "Hello, this is a YOLO prediction API using FastAPI!"}
 
60
 
61
  except Exception as e:
62
  raise HTTPException(status_code=500, detail=f"Error processing image: {str(e)}")
63
+
64
+
65
  @app.get("/test")
66
  async def read_root():
67
  return {"message": "TEST"}
 
69
 
70
  @app.get("/")
71
  async def read_root():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  return {"message": "Hello, this is a YOLO prediction API using FastAPI!"}