File size: 892 Bytes
86e9c13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
from fastapi import FastAPI, File, UploadFile 
from fastapi.middleware.cors import CORSMiddleware 
from PIL import Image 
import io 


from app.models.animal_vision import predict_animal 
from app.models.plant_vision import predict_plant 

app = FastAPI(

   title = 'BIONEXUS Image Intelligence API',
   version = '1.0.0'
)

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

@app.post('/animal/predict')
async def animal_predict(file: UploadFile = File(...)):
      image = Image.open(io.BytesIO(await file.read())).convert('RGB')
      result = predict_animal(image)
      return result

@app.post('/plant/predict') 
async def plant_predict(file: UploadFile = File(...)):
  image = Image.open(io.BytesIO(await file.read())).convert('RGB')
  result = predict_plant(image)  

  return result