Spaces:
Sleeping
Sleeping
File size: 4,066 Bytes
ae68995 f1650bd 9435ad1 ae68995 655cc9a ae68995 6497bd2 31bc1d3 6497bd2 ae68995 655cc9a ae68995 9435ad1 b94ea39 9435ad1 b94ea39 9435ad1 b94ea39 9435ad1 ae68995 b94ea39 9435ad1 ae68995 30b8c84 9435ad1 b94ea39 9435ad1 b94ea39 9435ad1 b94ea39 ae68995 30b8c84 1cb5e9a 0230985 ae68995 655cc9a ae68995 b0ff116 |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
import gradio as gr
from functools import partial
import csv
import pandas as pd
import ast
from datasets import load_dataset
from huggingface_hub import HfApi, HfFolder
data = pd.read_csv("./KB_gpt_v1.csv",index_col=0)
all_diseases = list(data['diseases'])
js = "(x) => {return alert('File Saved!!')}"
logged_in_users = {}
def login(username, password):
if (username, password) in [("admin", "pass1234"), ("admin2", "pass1234")]:
logged_in_users[username] = True
print(logged_in_users)
return True
else:
return False
def get_symp(symptoms,investigations,drugs,advices):
drug_dict = []
data_dict = eval(drugs)
print("DType of drugs is ",type(drugs))
print("Drugs :",drugs)
print("Data dict : ",data_dict)
for cat,med in data_dict.items():
for i in med:
drug_dict.append(i)
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))
def get_list(disease):
print(disease)
sympto = ast.literal_eval((data[data['diseases']==str(disease)]).iloc[0][1])
investigations = ast.literal_eval((data[data['diseases']==str(disease)]['investigations']).iloc[0])
drugs = ast.literal_eval((data[data['diseases']==str(disease)]["Drug type: Drugs"]).iloc[0])
advices = ast.literal_eval((data[data['diseases']==str(disease)]["Advices"]).iloc[0])
return sympto,investigations,drugs,advices
#------------------------------------------------
# api = HfApi()
# # Replace with your Hugging Face Spaces username and repository name
# username = "Add-Vishnu"
# repo_name = "cdss_kb_generation"
# # Replace with the CSV file name
filename = "demo1.csv"
# # Load the repository
# repo = HfFolder.(repo_name, api=api, username=username)
#---------------------------------------------------------
def save_data(disease,symp_data,invest_data,drug_data,advice_data):
user = ""
for username, logged_in in logged_in_users.items():
if logged_in:
user = username
print("In save:",user)
# Read the existing content of the CSV file
# file_path = repo.filename_to_path(filename)
existing_rows = []
with open(filename, "r") as csv_file:
print("Reading the data")
csv_reader = csv.reader(csv_file)
for row in csv_reader:
existing_rows.append(row)
print(existing_rows)
try:
print("In try")
with open("./demo1.csv", mode="a") as csvfile:
print("In open csv file",csvfile)
csv_writer = csv.writer(csvfile)
csv_writer.writerow([disease,symp_data,invest_data,drug_data,advice_data,user])
print("Done writing!!")
except:
print("An Exception occured")
with gr.Blocks() as demo:
with gr.Row():
disease = gr.Dropdown(all_diseases,label="Diseases")
with gr.Row():
fetch = gr.Button(value="Fetch")
symptoms=gr.Textbox(visible=False)
investigations = gr.Textbox(visible=False)
drugs = gr.Textbox(visible=False)
advices = gr.Textbox(visible=False)
disease.change(get_list,disease,[symptoms,investigations,drugs,advices])
with gr.Box():
symptoms_box = gr.CheckboxGroup(label="Symptoms",visible=False)
investigations_box = gr.CheckboxGroup(label="Investigations",visible=False)
# drugs_box = gr.Box(visible=False)
drugs_box = gr.CheckboxGroup(label="Drugs",visible=False)
advices_box = gr.CheckboxGroup(label="Advices",visible=False)
save = gr.Button(value="Save")
fetch.click(get_symp, inputs=[symptoms,investigations,drugs,advices],outputs=[symptoms_box,investigations_box,drugs_box,advices_box])
save.click(save_data,inputs=[disease,symptoms_box,investigations_box,drugs_box,advices_box],outputs=[]).then(fn=None,_js=js)
if __name__ == "__main__":
demo.launch(auth=login)
|