Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from keras.models import load_model
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
from util import classify, set_background
|
7 |
+
|
8 |
+
|
9 |
+
set_background('./bgs/bg5.png')
|
10 |
+
|
11 |
+
# set title
|
12 |
+
st.title('Pneumonia classification')
|
13 |
+
|
14 |
+
# set header
|
15 |
+
st.header('Please upload a chest X-ray image')
|
16 |
+
|
17 |
+
# upload file
|
18 |
+
file = st.file_uploader('', type=['jpeg', 'jpg', 'png'])
|
19 |
+
|
20 |
+
# load classifier
|
21 |
+
model = load_model('./model/pneumonia_classifier.h5')
|
22 |
+
|
23 |
+
# load class names
|
24 |
+
with open('./model/labels.txt', 'r') as f:
|
25 |
+
class_names = [a[:-1].split(' ')[1] for a in f.readlines()]
|
26 |
+
f.close()
|
27 |
+
|
28 |
+
# display image
|
29 |
+
if file is not None:
|
30 |
+
image = Image.open(file).convert('RGB')
|
31 |
+
st.image(image, use_column_width=True)
|
32 |
+
|
33 |
+
# classify image
|
34 |
+
class_name, conf_score = classify(image, model, class_names)
|
35 |
+
|
36 |
+
# write classification
|
37 |
+
st.write("## {}".format(class_name))
|
38 |
+
st.write("### score: {}%".format(int(conf_score * 1000) / 10))
|