[7f2816]: / hemorrhage.py

Download this file

94 lines (63 with data), 2.6 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import streamlit as st
from streamlit_discourse import st_discourse
import os
import pydicom
import cv2
import numpy as np
from fastai.vision.all import *
learner = load_learner("/home/tkrsh/Projects/Hemorrhage/model_b_1.pkl")
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
import time
from PIL import Image
from streamlit_disqus import st_disqus
from streamlit_echarts import st_echarts
def return_options():
pass
st.write(""" # Intracranial Hemorrhage Classification""")
st.write(""" ### In this Demo Version of our model we estimate whether the patient has Hemorrhage or the CT Scan is Normal """)
st.write(""" #### Generated Result will show a bar graph with probabilities of the cases""")
st.write("Source https://hemorrhage.tkrsh.com")
showWarningOnDirectExecution = False
@st.cache
def load_image(image_file):
img = Image.open(image_file)
return img
image_file = st.file_uploader("Upload Image Here ", type="jpg", accept_multiple_files=False, key=None, help=None, on_change=None, args=None, kwargs=None)
if image_file is not None:
file_details = {"FileName":image_file.name,"FileType":image_file.type}
# st.write(file_details)
img = load_image(image_file)
st.image(img,caption=f"Uploaded Image : {image_file.name}",)
with open(os.path.join("/home/tkrsh/Projects/Hemorrhage",image_file.name),"wb") as f:
f.write(image_file.getbuffer())
prediction = learner.predict(f"/home/tkrsh/Projects/Hemorrhage/{image_file.name}")
p_1 = round(float(prediction[-1][0]),1)
p_2 = round(float(prediction[-1][1]),1)
options = {
"xAxis": {
"type": "category",
"data": ["Hemorrhage ", "Normal "]
},
"yAxis": {"type": "value"},
"series": [
{"data":[p_1,p_2] , "type": "bar"}
],
}
st.success("Image Uploaded To The Server")
time.sleep(1)
st.success("Computing Predictions Please Wait")
time.sleep(4)
if int(prediction[1]) == 0:
st.write("#### Your Diagnosis: Hemorrhage is present """)
if int(prediction[1]) == 1:
st.write(""" #### Your Diagnosis: Scan Is Normal """)
st_echarts(options=options, height=400, width=700)
time.sleep(6)
st.write("##### Please reach out to clear you concerns we are here to help tkrsh@tkrsh.com")
# st_disqus("Tkrsh",url="https://tkrsh.disqus.com/")