Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +49 -0
- md_resnet34.pkl +3 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
from io import BytesIO
|
3 |
+
import requests
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
"""
|
7 |
+
# Plant Disease Diagnosis
|
8 |
+
This model utilizes Convolutional Neural Networks (CNN) to analyze and predict diseases on plant leaves. The diseases that can be identified include the following four types:
|
9 |
+
- **Black Spot**
|
10 |
+
- **Downy Mildew**
|
11 |
+
- **Leaf Rust**
|
12 |
+
- **Powdery Mildew**
|
13 |
+
"""
|
14 |
+
|
15 |
+
def predict(img):
|
16 |
+
st.image(img, caption="Your image", use_column_width=True)
|
17 |
+
pred, key, probs = learn_inf.predict(img)
|
18 |
+
# st.write(learn_inf.predict(img))
|
19 |
+
|
20 |
+
f"""
|
21 |
+
### Rediction result: {pred}
|
22 |
+
### Probability of {pred}: {probs[key].item()*100: .2f}%
|
23 |
+
"""
|
24 |
+
|
25 |
+
|
26 |
+
path = "./"
|
27 |
+
learn_inf = load_learner(path + "md_resnet34.pkl")
|
28 |
+
|
29 |
+
option = st.radio("", ["Upload Image", "Image URL"])
|
30 |
+
|
31 |
+
if option == "Upload Image":
|
32 |
+
uploaded_file = st.file_uploader("Please upload an image.")
|
33 |
+
|
34 |
+
if uploaded_file is not None:
|
35 |
+
img = PILImage.create(uploaded_file)
|
36 |
+
predict(img)
|
37 |
+
|
38 |
+
else:
|
39 |
+
url = st.text_input("Please input a url.")
|
40 |
+
|
41 |
+
if url != "":
|
42 |
+
try:
|
43 |
+
response = requests.get(url)
|
44 |
+
pil_img = PILImage.create(BytesIO(response.content))
|
45 |
+
predict(pil_img)
|
46 |
+
|
47 |
+
except:
|
48 |
+
st.text("Problem reading image from", url)
|
49 |
+
|
md_resnet34.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6a5981dcac20df0f4f6856f81635c7a3a66940ab8da39c6903543d33bffd7095
|
3 |
+
size 87498394
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastbook
|
2 |
+
altair<5
|