Spaces:
Sleeping
Sleeping
Update FastAPI_app.py
Browse files- FastAPI_app.py +9 -8
FastAPI_app.py
CHANGED
|
@@ -10,6 +10,7 @@ import asyncio
|
|
| 10 |
|
| 11 |
import uvicorn
|
| 12 |
import numpy as np
|
|
|
|
| 13 |
from PIL import Image
|
| 14 |
from fastapi import FastAPI, Form, UploadFile, File, Request, HTTPException
|
| 15 |
from fastapi.responses import HTMLResponse
|
|
@@ -142,16 +143,16 @@ def generate_recipe_qwen(ingredient_names):
|
|
| 142 |
# YOLOv8 model for ingredient detection
|
| 143 |
def infer_image(pil_image):
|
| 144 |
|
| 145 |
-
# Convert PIL
|
| 146 |
-
|
|
|
|
| 147 |
|
| 148 |
-
# Resize
|
| 149 |
-
|
| 150 |
-
img_resized = np.array(pil_resized)
|
| 151 |
|
| 152 |
# Inference with low threshold
|
| 153 |
-
results = _yolo_model(
|
| 154 |
-
|
| 155 |
detected = []
|
| 156 |
|
| 157 |
if results.boxes is not None and len(results.boxes) > 0:
|
|
@@ -347,4 +348,4 @@ def health():
|
|
| 347 |
|
| 348 |
# Run app
|
| 349 |
if __name__ == "__main__":
|
| 350 |
-
uvicorn.run("FastAPI_app:app", host="0.0.0.0", port=7860)
|
|
|
|
| 10 |
|
| 11 |
import uvicorn
|
| 12 |
import numpy as np
|
| 13 |
+
import cv2 as cv
|
| 14 |
from PIL import Image
|
| 15 |
from fastapi import FastAPI, Form, UploadFile, File, Request, HTTPException
|
| 16 |
from fastapi.responses import HTMLResponse
|
|
|
|
| 143 |
# YOLOv8 model for ingredient detection
|
| 144 |
def infer_image(pil_image):
|
| 145 |
|
| 146 |
+
# Convert PIL → OpenCV format
|
| 147 |
+
open_cv_image = np.array(pil_image)
|
| 148 |
+
open_cv_image = open_cv_image[:, :, ::-1].copy() # RGB → BGR
|
| 149 |
|
| 150 |
+
# Resize to 640x640, YOLOv8 default
|
| 151 |
+
img = cv.resize(open_cv_image, (640, 640))
|
|
|
|
| 152 |
|
| 153 |
# Inference with low threshold
|
| 154 |
+
results = _yolo_model(img, conf=0.2, iou=0.45, verbose=False)[0]
|
| 155 |
+
|
| 156 |
detected = []
|
| 157 |
|
| 158 |
if results.boxes is not None and len(results.boxes) > 0:
|
|
|
|
| 348 |
|
| 349 |
# Run app
|
| 350 |
if __name__ == "__main__":
|
| 351 |
+
uvicorn.run("FastAPI_app:app", host="0.0.0.0", port=7860, reload=True)
|