Spaces:
Sleeping
Sleeping
Commit
·
ae68995
1
Parent(s):
1862a97
Initial Commit - app.py
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from functools import partial
|
4 |
+
|
5 |
+
import csv
|
6 |
+
import pandas as pd
|
7 |
+
import ast
|
8 |
+
|
9 |
+
|
10 |
+
data = pd.read_csv("./KB_gpt_v1.csv",index_col=0)
|
11 |
+
|
12 |
+
all_diseases = list(data['diseases'])
|
13 |
+
|
14 |
+
js = "(x) => {return alert('File Saved!!')}"
|
15 |
+
|
16 |
+
logged_in_users = {}
|
17 |
+
def login(username, password):
|
18 |
+
if (username, password) in [("admin", "pass1234"), ("admin2", "pass1234")]:
|
19 |
+
logged_in_users[username] = True
|
20 |
+
print(logged_in_users)
|
21 |
+
return True
|
22 |
+
else:
|
23 |
+
return False
|
24 |
+
|
25 |
+
def get_symp(symptoms,investigations,drugs,advices):
|
26 |
+
all = []
|
27 |
+
data_dict = eval(drugs)
|
28 |
+
for cat,med in data_dict.items():
|
29 |
+
|
30 |
+
for i in med:
|
31 |
+
all.append(i)
|
32 |
+
return (gr.update(choices=eval(symptoms),visible=True,interactive=True)),(gr.update(choices=eval(investigations),visible=True,interactive=True)),(gr.update(choices=all,visible=True,interactive=True)),(gr.update(choices=eval(advices),visible=True,interactive=True))
|
33 |
+
|
34 |
+
|
35 |
+
def get_list(disease):
|
36 |
+
print(disease)
|
37 |
+
sympto = ast.literal_eval((data[data['diseases']==str(disease)]).iloc[0][1])
|
38 |
+
investigations = ast.literal_eval((data[data['diseases']==str(disease)]['investigations']).iloc[0])
|
39 |
+
drugs = ast.literal_eval((data[data['diseases']==str(disease)]["Drug type: Drugs"]).iloc[0])
|
40 |
+
advices = ast.literal_eval((data[data['diseases']==str(disease)]["Advices"]).iloc[0])
|
41 |
+
return sympto,investigations,drugs,advices
|
42 |
+
|
43 |
+
|
44 |
+
def save_data(disease,symp_data,invest_data,drug_data,advice_data):
|
45 |
+
user = ""
|
46 |
+
for username, logged_in in logged_in_users.items():
|
47 |
+
if logged_in:
|
48 |
+
user = username
|
49 |
+
try:
|
50 |
+
with open("demo1.csv", mode="a", newline="") as csvfile:
|
51 |
+
csv_writer = csv.writer(csvfile)
|
52 |
+
csv_writer.writerow([disease,symp_data,invest_data,drug_data,advice_data,user])
|
53 |
+
|
54 |
+
except:
|
55 |
+
print("An Exception occured")
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
with gr.Blocks() as demo:
|
60 |
+
with gr.Row():
|
61 |
+
disease = gr.Dropdown(all_diseases,label="Diseases")
|
62 |
+
with gr.Row():
|
63 |
+
fetch = gr.Button(value="Fetch")
|
64 |
+
symptoms=gr.Textbox(visible=False)
|
65 |
+
investigations = gr.Textbox(visible=False)
|
66 |
+
drugs = gr.Textbox(visible=False)
|
67 |
+
advices = gr.Textbox(visible=False)
|
68 |
+
disease.change(get_list,disease,[symptoms,investigations,drugs,advices])
|
69 |
+
with gr.Box():
|
70 |
+
symptoms_box = gr.CheckboxGroup(label="Symptoms",visible=False)
|
71 |
+
investigations_box = gr.CheckboxGroup(label="Investigations",visible=False)
|
72 |
+
# drugs_box = gr.Box(visible=False)
|
73 |
+
drugs_box = gr.CheckboxGroup(label="Drugs",visible=False)
|
74 |
+
advices_box = gr.CheckboxGroup(label="Advices",visible=False)
|
75 |
+
save = gr.Button(value="Save")
|
76 |
+
|
77 |
+
fetch.click(get_symp, inputs=[symptoms,investigations,drugs,advices],outputs=[symptoms_box,investigations_box,drugs_box,advices_box])
|
78 |
+
save.click(save_data,inputs=[disease,symptoms_box,investigations_box,drugs_box,advices_box],outputs=[]).then(fn=None,_js=js)
|
79 |
+
if __name__ == "__main__":
|
80 |
+
demo.launch(auth=login)
|