File size: 1,856 Bytes
42472b3 |
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 69 70 71 72 |
import streamlit as st
import pandas as pd
import numpy as np
from joblib import load
# Title :
st.title("Disease :blue[Detector] 🕵️")
# Reading CSVs :
data = pd.read_csv("files/Training.csv").drop("prognosis", axis=1)
ds = pd.read_csv("files/disease_description.csv")
pr = pd.read_csv("files/disease_precaution.csv")
# Columns (representing symptoms) :
dis= list(data.columns)
# Loading model and saved dictionary :
model = load("model.joblib")
pro = load("disease.joblib")
# Creating an array with zeros :
arr = np.zeros(135)
opt = st.multiselect(
"Please Select Your :red[Symptoms :]",
dis
)
# Creating a function to predict and store :
opt = list(opt)
def predictions(opt):
idx = []
for i in opt:
idx.append(dis.index(i))
for i in idx:
arr[i] = 1
arr[-1]= len(opt)
pred = model.predict([arr])
for key in pro.keys():
if pro[key] == pred[0]:
print(f'''Disease:{key}
Array:{arr}''')
return key
# Description :
def give_des(d):
return [ds[ds["Disease"]==d].Symptom_Description][0]
# Description :
def give_pre(d):
return list(pr[pr["Disease"]==d].Symptom_precaution_0)[0],list(pr[pr["Disease"]==d].Symptom_precaution_1)[0],list(pr[pr["Disease"]==d].Symptom_precaution_2)[0], list(pr[pr["Disease"]==d].Symptom_precaution_3)[0]
if st.button("Detect"):
cola, colb, colc = st.columns(3)
prognosis = predictions(opt)
description = give_des(prognosis)
p1, p2, p3, p4 = give_pre(prognosis)
with colb:
try:
st.header(prognosis)
st.subheader("Description :")
st.caption(list(description.values)[0])
st.subheader("Precaution :")
st.caption(f"- {p1}\n- {p2}\n- {p3}\n- {p4}")
except:
st.header(":red[Something Went Wrong] ⚠️")
|