-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (44 loc) · 1.57 KB
/
app.py
File metadata and controls
50 lines (44 loc) · 1.57 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from flask import Flask
from firebase import firebase
import cv2
import numpy as np
import os
import joblib
import urllib.request
#the brain of the mighty Project
def extract_color_histogram(image, bins=(8, 8, 8)):
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
hist = cv2.calcHist([hsv], [0, 1, 2], None, bins,
[0, 180, 0, 256, 0, 256])
cv2.normalize(hist, hist)
return hist.flatten()
#load fireabse realtime databse link
firebase = firebase.FirebaseApplication("https://_firebase app name_.firebaseio.com/", None)
app = Flask(__name__)
@app.route('/home/<pos>')
def classify(pos):
#get the link of the image from firebase realtime Database
string = '%s' % pos
data = firebase.get('/'+string, '')
link = data["url"]
#open the image using urllib.requests and convert the same into
#an array as opencv reads the image as an array
req = urllib.request.urlopen(link)
arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
#reshape the array
img = cv2.imdecode(arr, -1)
#load the model using joblib
model = joblib.load(os.path.abspath(os.path.dirname(__file__).replace("",""))+"/assets/model.sav")
#get the histogram
histt = extract_color_histogram(img)
histt2 = histt.reshape(1, -1)
#predict
prediction = model.predict(histt2)
acc = mse( , prediction)
#comapare the output to return the corresponding class
if prediction == [1]:
return "Pneumonia"
else:
return "Normal"
if __name__ == '__main__':
app.run(debug=True)