Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -73,4 +73,23 @@ async def read_root(): | |
| 73 |  | 
| 74 | 
             
            @app.get("/")
         | 
| 75 | 
             
            async def read_root():
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 76 | 
             
                return {"message": "Hello, this is a YOLO prediction API using FastAPI!"}
         | 
|  | |
| 73 |  | 
| 74 | 
             
            @app.get("/")
         | 
| 75 | 
             
            async def read_root():
         | 
| 76 | 
            +
                # Download image content from URL
         | 
| 77 | 
            +
                response = requests.get(image_url)
         | 
| 78 | 
            +
                response.raise_for_status()
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                # Open the image using PIL
         | 
| 81 | 
            +
                image = Image.open(io.BytesIO(response.content))
         | 
| 82 | 
            +
                # Perform YOLO prediction
         | 
| 83 | 
            +
                predictions = predict_yolo(https://s1.eestatic.com/2018/04/10/actualidad/actualidad_298735505_130172549_1000x500.jpg)
         | 
| 84 | 
            +
                
         | 
| 85 | 
            +
                # Draw bounding boxes on the image
         | 
| 86 | 
            +
                image_np = np.array(image)
         | 
| 87 | 
            +
                image_with_boxes = draw_boxes(image_np, predictions)
         | 
| 88 | 
            +
                
         | 
| 89 | 
            +
                # Save the image with bounding boxes
         | 
| 90 | 
            +
                image_with_boxes_path = f"/tmp/{file.filename.split('.')[0]}_with_boxes.jpg"
         | 
| 91 | 
            +
                cv2.imwrite(image_with_boxes_path, cv2.cvtColor(image_with_boxes, cv2.COLOR_RGB2BGR))
         | 
| 92 | 
            +
                
         | 
| 93 | 
            +
                # Render the HTML with the image and bounding boxes
         | 
| 94 | 
            +
                return templates.TemplateResponse("prediction.html", {"request": file, "image_path": image_with_boxes_path})
         | 
| 95 | 
             
                return {"message": "Hello, this is a YOLO prediction API using FastAPI!"}
         |