Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,15 +14,37 @@ CITATION_BUTTON_TEXT = """@article{2022,
|
|
14 |
month={Jun} }
|
15 |
"""
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
with open('healthsheet.json', 'r') as file:
|
19 |
json_data = json.load(file)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
healthsheet += f"# {header}\n\n"
|
24 |
-
for var_name, question in json_data[header].items():
|
25 |
-
healthsheet += f"## {question}\n\n"
|
26 |
|
27 |
with gr.Blocks() as demo:
|
28 |
gr.HTML("<h1><center>Healthsheet Creator! πͺπβ¨<h1><center>")
|
@@ -44,8 +66,9 @@ with gr.Blocks() as demo:
|
|
44 |
for tab_name in json_data:
|
45 |
with gr.Tab(tab_name):
|
46 |
for var_name, label_text in json_data[tab_name].items():
|
47 |
-
gr.Textbox(
|
48 |
-
|
|
|
49 |
|
50 |
with gr.Column():
|
51 |
gr.Markdown("This is where your Markdown-formatted healthsheet will appear! You can copy and paste it into your dataset card.")
|
|
|
14 |
month={Jun} }
|
15 |
"""
|
16 |
|
17 |
+
def initialize_healthsheet(json_data):
|
18 |
+
healthsheet_dict = {}
|
19 |
+
for header in json_data:
|
20 |
+
healthsheet_dict[header] = {}
|
21 |
+
for var_name, question in json_data[header].items():
|
22 |
+
healthsheet_dict[header][var_name] = {
|
23 |
+
'question': question,
|
24 |
+
'answer': None
|
25 |
+
}
|
26 |
+
return healthsheet_dict
|
27 |
+
|
28 |
+
def print_healthsheet(healthsheet_dict):
|
29 |
+
healthsheet = ""
|
30 |
+
for header in healthsheet_dict:
|
31 |
+
healthsheet += f"# {header}\n\n"
|
32 |
+
for var_name in json_data[header]:
|
33 |
+
healthsheet += f"## {var_name['question']}\n\n"
|
34 |
+
healthsheet += f"## {var_name['answer']}\n\n"
|
35 |
+
return healthsheet
|
36 |
+
|
37 |
+
def update_healthsheet(healthsheet_dict, header, var_name, answer):
|
38 |
+
healthsheet_dict[header][var_name] = answer
|
39 |
+
healthsheet = print_healthsheet(healthsheet_dict)
|
40 |
+
return healthsheet_dict, healthsheet
|
41 |
+
|
42 |
+
|
43 |
with open('healthsheet.json', 'r') as file:
|
44 |
json_data = json.load(file)
|
45 |
|
46 |
+
healthsheet_dict = initialize_healthsheet(json_data)
|
47 |
+
healthsheet = print_healthsheet(healthsheet_dict)
|
|
|
|
|
|
|
48 |
|
49 |
with gr.Blocks() as demo:
|
50 |
gr.HTML("<h1><center>Healthsheet Creator! πͺπβ¨<h1><center>")
|
|
|
66 |
for tab_name in json_data:
|
67 |
with gr.Tab(tab_name):
|
68 |
for var_name, label_text in json_data[tab_name].items():
|
69 |
+
answer = gr.Textbox(label=label_text, lines=3)
|
70 |
+
update_btn = gr.Button("Update")
|
71 |
+
update_btn.click(update_healthsheet, input=[healthsheet_dict, header, var_name, answer], output=[healthsheet_dict, healthsheet])
|
72 |
|
73 |
with gr.Column():
|
74 |
gr.Markdown("This is where your Markdown-formatted healthsheet will appear! You can copy and paste it into your dataset card.")
|