Spaces:
Runtime error
Runtime error
Gaeulove924
commited on
Commit
•
718d11e
1
Parent(s):
88ef0fe
Upload 3 files
Browse files- app.py +46 -0
- requirements(1).txt +2 -0
- resnet50_stage-2.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
from io import BytesIO
|
3 |
+
import requests
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
"""
|
7 |
+
# HeartNet
|
8 |
+
This is a classifier for images of 12-lead EKGs. It will attempt to detect whether the EKG indicates an acute MI. It was trained on simulated images.
|
9 |
+
"""
|
10 |
+
|
11 |
+
def predict(img):
|
12 |
+
st.image(img, caption="Your image", use_column_width=True)
|
13 |
+
pred, key, probs = learn_inf.predict(img)
|
14 |
+
# st.write(learn_inf.predict(img))
|
15 |
+
|
16 |
+
f"""
|
17 |
+
## This **{'is ' if pred == 'mi' else 'is not'}** an MI (heart attack).
|
18 |
+
### Rediction result: {pred}
|
19 |
+
### Probability of {pred}: {probs[key].item()*100: .2f}%
|
20 |
+
"""
|
21 |
+
|
22 |
+
|
23 |
+
path = "./"
|
24 |
+
learn_inf = load_learner(path + "demo_model.pkl")
|
25 |
+
|
26 |
+
option = st.radio("", ["Upload Image", "Image URL"])
|
27 |
+
|
28 |
+
if option == "Upload Image":
|
29 |
+
uploaded_file = st.file_uploader("Please upload an image.")
|
30 |
+
|
31 |
+
if uploaded_file is not None:
|
32 |
+
img = PILImage.create(uploaded_file)
|
33 |
+
predict(img)
|
34 |
+
|
35 |
+
else:
|
36 |
+
url = st.text_input("Please input a url.")
|
37 |
+
|
38 |
+
if url != "":
|
39 |
+
try:
|
40 |
+
response = requests.get(url)
|
41 |
+
pil_img = PILImage.create(BytesIO(response.content))
|
42 |
+
predict(pil_img)
|
43 |
+
|
44 |
+
except:
|
45 |
+
st.text("Problem reading image from", url)
|
46 |
+
|
requirements(1).txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastbook
|
2 |
+
altair<5
|
resnet50_stage-2.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:98881df1ff32671e65854b41d67e33f394ff486440d25609b1920089093587fb
|
3 |
+
size 102946836
|