Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from ultralytics import YOLO
|
2 |
|
3 |
import asyncio
|
|
|
4 |
from fastapi import FastAPI
|
5 |
from fastapi.middleware.cors import CORSMiddleware
|
6 |
import requests
|
@@ -20,11 +21,16 @@ app.add_middleware(
|
|
20 |
|
21 |
names = {0: 'breaking-stage', 1: 'half-riping-stage', 2: 'overripe un-healthy', 3: 'ripe', 4: 'ripe_with_consumable_disease', 5: 'unripe'}
|
22 |
@app.get("/predict")
|
23 |
-
async def get_prediction():
|
|
|
|
|
|
|
|
|
|
|
24 |
# Predict with the model
|
25 |
-
results = model(
|
26 |
# View results
|
27 |
for r in results:
|
28 |
-
print(names[int(r.probs
|
29 |
|
30 |
return r.probs
|
|
|
1 |
from ultralytics import YOLO
|
2 |
|
3 |
import asyncio
|
4 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException
|
5 |
from fastapi import FastAPI
|
6 |
from fastapi.middleware.cors import CORSMiddleware
|
7 |
import requests
|
|
|
21 |
|
22 |
names = {0: 'breaking-stage', 1: 'half-riping-stage', 2: 'overripe un-healthy', 3: 'ripe', 4: 'ripe_with_consumable_disease', 5: 'unripe'}
|
23 |
@app.get("/predict")
|
24 |
+
async def get_prediction(file: UploadFile = File(...)):
|
25 |
+
|
26 |
+
file_name = file.filename
|
27 |
+
print(file_name)
|
28 |
+
with open(file_name, "wb") as file_object:
|
29 |
+
file_object.write(file.file.read())
|
30 |
# Predict with the model
|
31 |
+
results = model(file_name)
|
32 |
# View results
|
33 |
for r in results:
|
34 |
+
print(names[int(r.probs.top1)])
|
35 |
|
36 |
return r.probs
|