File size: 1,761 Bytes
3344baa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from tensorflow import image
from keras import models
import numpy as np
from PIL import Image
import pandas as pd

st.title("Rice Disease Classifier 🌾")

desc = pd.read_csv("files/description.csv")
model  = models.load_model("models/0.3/model.h5")

dis = list(desc.disease.values)

def image_classifier(inp):
    try:
        inp = image.resize(inp, (256,256))
        inp = np.expand_dims(inp,0)
        pred= model.predict(inp)
        return dis[np.argmax(pred)] , f"Confidence - {round(max(pred[0])*100,2)}%"
    except:
        return "Healthy", "Confidence - 0%"

def detail(pro):
    x = desc[desc["disease"]==pro]
    return list(x["hindi"])[0], list(x["desc"])[0], list(x["hndesc"])[0], list(x["pre"])[0], list(x["hnpre"])[0]


cho = st.file_uploader("Upload Image From Gallery", type=['png','jpg','jpeg','webp'])
img = ""

if cho is not None:
    img = Image.open(cho)

st.write("or")
if st.button("Open Camera"):
    cam = st.camera_input("Take image")
    if cam is not None:
        img = Image.open(cam)


if st.button("Detect"):
    col1,col2,col3 = st.columns(3)
    pro, conf = image_classifier(img)
    hin, des, hnd, pre, hnp = detail(pro)
    try:
        with col2:
            st.image(img)
            st.write("\n\n")
            st.header(pro)
            st.subheader(f"({hin})")
            st.subheader(conf)
            st.write("\n\n\n\n")

            st.subheader(f"Description :")
            st.write(des)
            st.write("\n\n")
            st.write(hnd)
            st.write("\n\n\n")

            st.subheader(f"Precautions :")
            st.write(pre)
            st.write("\n\n")
            st.write(hnp)
    except:
        with col2:
            st.subheader(":red[Enter Valid Input]")