File size: 708 Bytes
5bab6dc
 
5cb1a46
 
21011da
5cb1a46
299d49b
ff9efc0
feca41c
5cb1a46
21011da
 
 
 
 
 
 
 
5cb1a46
 
ce3d5e4
11d64cf
59fdf33
299d49b
 
a1ef609
 
fec33d3
3e53a2c
ce3d5e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from ultralytics import YOLO

import asyncio
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import requests
model = YOLO('best.pt')  # load a custom model

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)



names = {0: 'breaking-stage', 1: 'half-riping-stage', 2: 'overripe un-healthy', 3: 'ripe', 4: 'ripe_with_consumable_disease', 5: 'unripe'}   
@app.get("/predict")
async def get_prediction():
    # Predict with the model
    results = model('test.jpg') 
    # View results
    for r in results:
        print(names[int(r.probs[top1])]) 

    return r.probs