kedimestan commited on
Commit
990cee3
1 Parent(s): 5e6426e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,5 +1,4 @@
1
  from fastapi import FastAPI, UploadFile, File
2
- from ultralytics import YOLO
3
  from transformers import pipeline
4
  from PIL import Image
5
  import io
@@ -8,16 +7,22 @@ import io
8
  app = FastAPI()
9
 
10
  # Load the YOLOv5 model for object detection
11
- model = YOLO("yolov8n.pt")
 
 
 
 
 
 
12
 
13
  @app.post("/detect_objects/")
14
  async def detect_objects(file: UploadFile = File(...)):
15
  # Read image from uploaded file
16
  image_bytes = await file.read()
17
- image = Image.open(io.BytesIO(image_bytes))
18
 
19
  # Perform object detection
20
- results = model(image)
21
 
22
  # Extract bounding box coordinates and labels
23
  bounding_boxes = []
 
1
  from fastapi import FastAPI, UploadFile, File
 
2
  from transformers import pipeline
3
  from PIL import Image
4
  import io
 
7
  app = FastAPI()
8
 
9
  # Load the YOLOv5 model for object detection
10
+ from transformers import pipeline
11
+ from PIL import Image
12
+
13
+ pipe = pipeline("object-detection", model="facebook/detr-resnet-50")
14
+
15
+
16
+ bounding_boxes = pipe(image)
17
 
18
  @app.post("/detect_objects/")
19
  async def detect_objects(file: UploadFile = File(...)):
20
  # Read image from uploaded file
21
  image_bytes = await file.read()
22
+ image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
23
 
24
  # Perform object detection
25
+ results = pipe(image)
26
 
27
  # Extract bounding box coordinates and labels
28
  bounding_boxes = []