Commit 8e8fb21b authored by Kavindu Randika's avatar Kavindu Randika

Merge branch 'dev-it18141252' into 'master'

Dev it18141252

See merge request !8
parents 347c156d 11fc9684
...@@ -13,9 +13,21 @@ ...@@ -13,9 +13,21 @@
- .\env\Scripts\activate - .\env\Scripts\activate
- uvicorn main:app --reload - uvicorn main:app --reload
## Export Dependencies ## Export Dependencies
- .\env\Scripts\activate - .\env\Scripts\activate
- pip freeze > requirements.txt - pip freeze > requirements.txt
test change ## Deploy to deta.sh
\ No newline at end of file
- Install deta CLI
`iwr https://get.deta.dev/cli.ps1 -useb | iex`
- Login to deta
`deta login`
- Deploy
`deta new`
from pymongo import MongoClient from pymongo import MongoClient
conn = MongoClient("mongodb+srv://skin-disease:skindis123@cluster0.bv8ia.mongodb.net/skinDiseaseDB?retryWrites=true&w=majority") conn = MongoClient("mongodb+srv://skin-disease:skindis123@cluster0.bv8ia.mongodb.net/skinDiseaseDB?retryWrites=true&w=majority", tls=True, tlsAllowInvalidCertificates=True)
db = conn['skinDiseaseDB']
disease_collection = db['disease']
#mongodb+srv://skin-disease:skindis123@cluster0.bv8ia.mongodb.net/test #mongodb+srv://skin-disease:skindis123@cluster0.bv8ia.mongodb.net/test
\ No newline at end of file
from pydantic import BaseModel from pydantic import BaseModel
from typing import Optional
class Disease(BaseModel): class Disease(BaseModel):
name: str name: str
description: str description: Optional[str]=""
\ No newline at end of file \ No newline at end of file
from fastapi import APIRouter, File, UploadFile from fastapi import APIRouter, File, UploadFile
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
...@@ -7,10 +8,15 @@ import pandas as pd ...@@ -7,10 +8,15 @@ 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 schemas.disease import diseasesEntity
prediction = APIRouter() prediction = APIRouter()
class Symptoms(BaseModel):
symptoms: List[int]
batch_size = 32 batch_size = 32
img_height = 180 img_height = 180
img_width = 180 img_width = 180
...@@ -36,12 +42,13 @@ def read_imagefile( image:UploadFile ): ...@@ -36,12 +42,13 @@ def read_imagefile( image:UploadFile ):
return None return None
# PREDICT DISEASE FROM SYMPTOMSES
@prediction.post('/api/predictions/symptoms') @prediction.post('/api/predictions/symptoms')
async def predict_symptoms(symptoms: List[int]): async def predict_symptoms(symptoms: Symptoms):
try: try:
data = load_data_json('./data.json') data = load_data_json('./data.json')
threshold = 0.5 threshold = 0.5
input = set(symptoms) input = set(symptoms.symptoms)
output = [] output = []
for key in data.keys(): for key in data.keys():
numbers = [int(i) for i in key.split(',') if int(i) != 0] numbers = [int(i) for i in key.split(',') if int(i) != 0]
...@@ -49,12 +56,16 @@ async def predict_symptoms(symptoms: List[int]): ...@@ -49,12 +56,16 @@ async def predict_symptoms(symptoms: List[int]):
score = len(list(input&set(numbers)))/lenght score = len(list(input&set(numbers)))/lenght
if score>=threshold: if score>=threshold:
output.append(data.get(key)) output.append(data.get(key))
diseases = diseasesEntity(disease_collection.find({"name": {"$in": output}}))
return {"success": True, "result": output} return {"success": True, "result": diseases}
except error: except error:
return {"success": False, "msg": error} return {"success": False, "msg": error}
# PREDICT DISEASE FROM PICTURES
@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:
......
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