Spaces:
Runtime error
Runtime error
File size: 1,389 Bytes
6d90422 f9c2b28 6d90422 20f3cf4 6d90422 247db63 f9c2b28 |
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 |
from fastai.vision.all import *
from io import BytesIO
import requests
import streamlit as st
"""
# HeartNet
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.
"""
def predict(img):
st.image(img, caption="Your image", use_column_width=True)
pred, pred_idx, probs = learn_inf.predict(img) # 修改此行,添加了 pred_idx
# st.write(learn_inf.predict(img))
f"""
## This leaf is affected by **{pred}**.
### Prediction result: {pred}
### Probability of {pred}: {probs[pred_idx].item() * 100:.2f}%
"""
st.title("Rice Leaf Disease Classifier")
st.write("Upload a rice leaf image to predict the disease.")
path = "./"
learn_inf = load_learner(path + "demo_model.pkl")
option = st.radio("", ["Upload Image", "Image URL"])
if option == "Upload Image":
uploaded_file = st.file_uploader("Please upload an image.")
if uploaded_file is not None:
img = PILImage.create(uploaded_file)
predict(img)
else:
url = st.text_input("Please input a url.")
if url != "":
try:
response = requests.get(url)
pil_img = PILImage.create(BytesIO(response.content))
predict(pil_img)
except Exception as e:
st.text("Problem reading image from " + url)
st.text(str(e)) |