Commit b18efe96 authored by Kavindu Randika's avatar Kavindu Randika

Diseases with descriptions

parent 8e8fb21b
absl-py==0.14.0
asgiref==3.4.1 asgiref==3.4.1
astunparse==1.6.3
cachetools==4.2.2
certifi==2021.5.30
charset-normalizer==2.0.6
clang==5.0
click==8.0.1 click==8.0.1
colorama==0.4.4 colorama==0.4.4
dnspython==2.1.0 dnspython==1.16.0
fastapi==0.68.1 fastapi==0.68.1
flatbuffers==1.12
gast==0.4.0
google-auth==1.35.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.40.0
h11==0.12.0 h11==0.12.0
h5py==3.1.0
idna==3.2
keras==2.6.0
Keras-Preprocessing==1.1.2
Markdown==3.3.4
numpy==1.19.5
oauthlib==3.1.1
opt-einsum==3.3.0
pandas==1.3.3
Pillow==8.3.2
protobuf==3.18.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pydantic==1.8.2 pydantic==1.8.2
pymongo==3.12.0 pymongo==3.12.0
python-dateutil==2.8.2
python-multipart==0.0.5 python-multipart==0.0.5
pytz==2021.1 six==1.16.0
requests==2.26.0
requests-oauthlib==1.3.0
rsa==4.7.2
six==1.15.0
starlette==0.14.2 starlette==0.14.2
tensorboard==2.6.0 typing-extensions==3.10.0.2
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.0
tensorflow-cpu==2.6.0
tensorflow-estimator==2.6.0
termcolor==1.1.0
typing-extensions==3.7.4.3
urllib3==1.26.7
uvicorn==0.15.0 uvicorn==0.15.0
Werkzeug==2.0.1
wrapt==1.12.1
\ No newline at end of file
from fastapi import APIRouter, File, UploadFile from fastapi import APIRouter, File, UploadFile
from pydantic import BaseModel from pydantic import BaseModel
import tensorflow as tf # import tensorflow as tf
from tensorflow import keras # from tensorflow import keras
from typing import List from typing import List
from os import error from os import error
import pandas as pd # import pandas as pd
import numpy as np # import numpy as np
import json import json
from keras.preprocessing import image #from keras.preprocessing import image
from config.db import disease_collection from config.db import disease_collection
from schemas.disease import diseasesEntity from schemas.disease import diseasesEntity
...@@ -57,7 +57,7 @@ async def predict_symptoms(symptoms: Symptoms): ...@@ -57,7 +57,7 @@ async def predict_symptoms(symptoms: Symptoms):
if score>=threshold: if score>=threshold:
output.append(data.get(key)) output.append(data.get(key))
diseases = diseasesEntity(disease_collection.find({"name": {"$in": output}})) diseases = diseasesEntity(disease_collection.find({"name": {"$in": output}}))
return {"success": True, "result": diseases} return {"success": True, "result": diseases}
...@@ -69,30 +69,30 @@ async def predict_symptoms(symptoms: Symptoms): ...@@ -69,30 +69,30 @@ async def predict_symptoms(symptoms: Symptoms):
@prediction.post('/api/predictions/picture') @prediction.post('/api/predictions/picture')
async def predict_symptoms(req_file: UploadFile = File(...)): async def predict_symptoms(req_file: UploadFile = File(...)):
try: try:
img = read_imagefile(req_file) # img = read_imagefile(req_file)
if img is None: # if img is None:
return {"success": False, "msg": 'Not a valid data format'} # return {"success": False, "msg": 'Not a valid data format'}
model_path = './xception' # model_path = './xception'
image_path = "./temp_images/temp_image.jpg" # image_path = "./temp_images/temp_image.jpg"
#load model # #load model
model = keras.models.load_model(model_path) # model = keras.models.load_model(model_path)
#load data # #load data
load_img = image.load_img(image_path, target_size=(img_height, img_width)) # load_img = image.load_img(image_path, target_size=(img_height, img_width))
img_array = image.img_to_array(load_img) # img_array = image.img_to_array(load_img)
img_array = tf.expand_dims(img_array, 0) # img_array = tf.expand_dims(img_array, 0)
#predict # #predict
predictions = model.predict(img_array, batch_size) # predictions = model.predict(img_array, batch_size)
score = tf.nn.softmax(predictions[0]) # score = tf.nn.softmax(predictions[0])
#return # #return
prediction = class_names[np.argmax(score)] # prediction = class_names[np.argmax(score)]
return {"success": True, "result": prediction} return {"success": True, "result": req_file.filename}
except error: except error:
return {"success": False, "msg": error} return {"success": False, "msg": error}
......
def diseaseEntity(item) -> dict: def diseaseEntity(item) -> dict:
return { return {
"id":str(item["id"]),
"name": item["name"], "name": item["name"],
"description": item["description"], "description": item["description"],
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment