freeball0328 commited on
Commit
1f74b34
1 Parent(s): 59e267e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -28
app.py CHANGED
@@ -1,30 +1,48 @@
 
 
 
1
  import streamlit as st
2
 
3
- # 示例图片的路径
4
- example_images = {
5
- "Wind Energy": "exwind.jpg"
6
- }
7
-
8
- # 用户选择的能源类型
9
- category = st.radio("Choose the energy type of the image to upload", ["Hydro Energy", "Wind Energy", "Solar Energy"])
10
-
11
- # 显示选定能源类型的示例图片
12
- if category:
13
- st.write(f"Example of a {category} image:")
14
- st.image(example_images[category], caption=f"Example {category}", use_column_width=True)
15
-
16
- option = st.radio("", ["Upload Image", "Image URL"])
17
- if option == "Upload Image":
18
- uploaded_file = st.file_uploader("Please upload an image.")
19
- if uploaded_file is not None:
20
- img = PILImage.create(uploaded_file)
21
- predict(img, category)
22
- else:
23
- url = st.text_input("Please input a url.")
24
- if url:
25
- try:
26
- response = requests.get(url)
27
- pil_img = PILImage.create(BytesIO(response.content))
28
- predict(pil_img, category)
29
- except requests.exceptions.RequestException as e:
30
- st.error(f"Problem reading image from the URL: {url}\nError: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ from io import BytesIO
3
+ import requests
4
  import streamlit as st
5
 
6
+ # 标题和应用描述
7
+ st.title("HeartNet")
8
+ st.write("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
+ st.write("## Example of an EKG image to upload")
12
+ st.image("exwind.jpg", caption="Example EKG Image", use_column_width=True)
13
+
14
+ def predict(img):
15
+ st.image(img, caption="Your image", use_column_width=True)
16
+ pred, key, probs = learn_inf.predict(img)
17
+
18
+ result_message = f"""
19
+ ## This **{'is ' if pred == 'mi' else 'is not'}** an MI (heart attack).
20
+ ### Prediction result: {pred}
21
+ ### Probability of {pred}: {probs[key].item()*100: .2f}%
22
+ """
23
+ st.write(result_message)
24
+
25
+ # 加载模型
26
+ path = "./"
27
+ learn_inf = load_learner(path + "resnet34_stage_4.pkl")
28
+
29
+ # 用户上传图片或提供图片 URL
30
+ option = st.radio("", ["Upload Image", "Image URL"])
31
+
32
+ if option == "Upload Image":
33
+ uploaded_file = st.file_uploader("Please upload an image.")
34
+
35
+ if uploaded_file is not None:
36
+ img = PILImage.create(uploaded_file)
37
+ predict(img)
38
+
39
+ else:
40
+ url = st.text_input("Please input a URL for an image.")
41
+
42
+ if url != "":
43
+ try:
44
+ response = requests.get(url)
45
+ pil_img = PILImage.create(BytesIO(response.content))
46
+ predict(pil_img)
47
+ except Exception as e:
48
+ st.error(f"Problem reading image from the URL. Please check the URL and try again. Error: {str(e)}")