Spaces:
Sleeping
Sleeping
Commit
·
103159c
1
Parent(s):
655cc9a
Updated drug_dict
Browse files
app.py
CHANGED
|
@@ -32,7 +32,6 @@ def get_symp(symptoms,investigations,drugs,advices):
|
|
| 32 |
print("Drugs :",drugs)
|
| 33 |
print("Data dict : ",data_dict)
|
| 34 |
for cat,med in data_dict.items():
|
| 35 |
-
|
| 36 |
for i in med:
|
| 37 |
drug_dict.append(i)
|
| 38 |
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))
|
|
@@ -58,12 +57,21 @@ filename = "demo1.csv"
|
|
| 58 |
# # Load the repository
|
| 59 |
# repo = HfFolder.(repo_name, api=api, username=username)
|
| 60 |
#---------------------------------------------------------
|
| 61 |
-
def save_data(disease,symp_data,invest_data,drug_data,advice_data):
|
| 62 |
user = ""
|
| 63 |
for username, logged_in in logged_in_users.items():
|
| 64 |
if logged_in:
|
| 65 |
user = username
|
| 66 |
print("In save:",user)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# Read the existing content of the CSV file
|
| 68 |
# file_path = repo.filename_to_path(filename)
|
| 69 |
existing_rows = []
|
|
@@ -73,12 +81,13 @@ def save_data(disease,symp_data,invest_data,drug_data,advice_data):
|
|
| 73 |
for row in csv_reader:
|
| 74 |
existing_rows.append(row)
|
| 75 |
print(existing_rows)
|
|
|
|
| 76 |
try:
|
| 77 |
print("In try")
|
| 78 |
with open("./demo1.csv", mode="a") as csvfile:
|
| 79 |
print("In open csv file",csvfile)
|
| 80 |
csv_writer = csv.writer(csvfile)
|
| 81 |
-
csv_writer.writerow([disease,symp_data,invest_data,
|
| 82 |
print("Done writing!!")
|
| 83 |
except:
|
| 84 |
print("An Exception occured")
|
|
@@ -104,6 +113,6 @@ with gr.Blocks() as demo:
|
|
| 104 |
save = gr.Button(value="Save")
|
| 105 |
|
| 106 |
fetch.click(get_symp, inputs=[symptoms,investigations,drugs,advices],outputs=[symptoms_box,investigations_box,drugs_box,advices_box])
|
| 107 |
-
save.click(save_data,inputs=[disease,symptoms_box,investigations_box,drugs_box,advices_box],outputs=[]).then(fn=None,_js=js)
|
| 108 |
if __name__ == "__main__":
|
| 109 |
demo.launch(auth=login)
|
|
|
|
| 32 |
print("Drugs :",drugs)
|
| 33 |
print("Data dict : ",data_dict)
|
| 34 |
for cat,med in data_dict.items():
|
|
|
|
| 35 |
for i in med:
|
| 36 |
drug_dict.append(i)
|
| 37 |
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))
|
|
|
|
| 57 |
# # Load the repository
|
| 58 |
# repo = HfFolder.(repo_name, api=api, username=username)
|
| 59 |
#---------------------------------------------------------
|
| 60 |
+
def save_data(disease,symp_data,invest_data,drug_data,advice_data,drug_dict):
|
| 61 |
user = ""
|
| 62 |
for username, logged_in in logged_in_users.items():
|
| 63 |
if logged_in:
|
| 64 |
user = username
|
| 65 |
print("In save:",user)
|
| 66 |
+
|
| 67 |
+
drug_dict = eval(drug_dict)
|
| 68 |
+
drug_keys = drug_dict.keys()
|
| 69 |
+
user_drug_dict = {}
|
| 70 |
+
for i in drug_data:
|
| 71 |
+
for j in drug_keys:
|
| 72 |
+
if i in drug_dict[j]:
|
| 73 |
+
user_drug_dict.setdefault(j, []).append(i)
|
| 74 |
+
# ---------------------------------------------
|
| 75 |
# Read the existing content of the CSV file
|
| 76 |
# file_path = repo.filename_to_path(filename)
|
| 77 |
existing_rows = []
|
|
|
|
| 81 |
for row in csv_reader:
|
| 82 |
existing_rows.append(row)
|
| 83 |
print(existing_rows)
|
| 84 |
+
# ----------------------------------------------
|
| 85 |
try:
|
| 86 |
print("In try")
|
| 87 |
with open("./demo1.csv", mode="a") as csvfile:
|
| 88 |
print("In open csv file",csvfile)
|
| 89 |
csv_writer = csv.writer(csvfile)
|
| 90 |
+
csv_writer.writerow([disease,symp_data,invest_data,user_drug_dict,advice_data,user])
|
| 91 |
print("Done writing!!")
|
| 92 |
except:
|
| 93 |
print("An Exception occured")
|
|
|
|
| 113 |
save = gr.Button(value="Save")
|
| 114 |
|
| 115 |
fetch.click(get_symp, inputs=[symptoms,investigations,drugs,advices],outputs=[symptoms_box,investigations_box,drugs_box,advices_box])
|
| 116 |
+
save.click(save_data,inputs=[disease,symptoms_box,investigations_box,drugs_box,advices_box,drugs],outputs=[]).then(fn=None,_js=js)
|
| 117 |
if __name__ == "__main__":
|
| 118 |
demo.launch(auth=login)
|