NikilDGr8 commited on
Commit
b6b8268
·
verified ·
1 Parent(s): 57f1a14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -15
app.py CHANGED
@@ -24,6 +24,18 @@ questions = [
24
  "What treatment plan do you recommend?"
25
  ]
26
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  oral_health_assessment_form = [
28
  "Doctor’s Name",
29
  "Location",
@@ -81,7 +93,17 @@ def fill_textboxes(context):
81
  for question in questions:
82
  answer = generate_answer(question, context)
83
  answers.append(answer)
84
- return answers
 
 
 
 
 
 
 
 
 
 
85
 
86
  # Supabase configuration
87
  supabase: Client = create_client(url, key)
@@ -94,10 +116,11 @@ def main(audio, doctor_name, location):
94
  return [context] * (len(oral_health_assessment_form) - 2) # Adjust for the number of fields
95
 
96
  answers = fill_textboxes(context)
97
- answers.insert(0, location) # Add location
98
- answers.insert(0, doctor_name) # Add doctor name
 
99
 
100
- return answers
101
 
102
  def save_answers(doctor_name, location, patient_name, age, gender, chief_complaint, medical_history, dental_history, clinical_findings, treatment_plan, referred_to):
103
  current_datetime = datetime.now().isoformat()
@@ -203,21 +226,27 @@ with gr.Blocks() as demo:
203
  return [context] * (len(oral_health_assessment_form) - 3) # Adjust for the number of fields
204
 
205
  answers = fill_textboxes(context)
206
- answers.insert(0, location) # Add location
207
- answers.insert(0, doctor_name) # Add doctor name
 
208
 
209
- return [doctor_name, location] + [""] + answers # Patient name is left empty
210
 
211
- transcribe_button.click(fn=update_textboxes, inputs=[audio_input, doctor_name_input, location_input], outputs=[doctor_name_display, location_display] + [patient_name_input] + textboxes_left + textboxes_right)
212
  submit_button = gr.Button("Submit", elem_id="submit_button")
213
- output_html = gr.HTML(label="Submitted Answers")
214
- submit_button.click(fn=save_answers, inputs=[doctor_name_display, location_display, patient_name_input] + textboxes_left + textboxes_right + [dropdown_referred], outputs=output_html)
 
 
 
 
215
 
216
- # Third tab for CSV download
217
  with gr.Tab("Download CSV"):
218
- download_button = gr.Button("Download Table as CSV")
219
- download_csv_output = gr.File(label="Download CSV")
220
- download_button.click(fn=gradio_download, inputs=[], outputs=download_csv_output)
 
221
 
222
- # Launch the app
223
  demo.launch()
 
24
  "What treatment plan do you recommend?"
25
  ]
26
 
27
+ # List of form fields in the correct order
28
+ form_fields = [
29
+ "Age",
30
+ "Gender",
31
+ "Chief complaint",
32
+ "Dental history",
33
+ "Clinical Findings",
34
+ "Treatment plan",
35
+ "Referred to"
36
+ ]
37
+
38
+ # Oral Health Assessment Form
39
  oral_health_assessment_form = [
40
  "Doctor’s Name",
41
  "Location",
 
93
  for question in questions:
94
  answer = generate_answer(question, context)
95
  answers.append(answer)
96
+
97
+ # Map answers to form fields in the correct order
98
+ return {
99
+ "Age": answers[0],
100
+ "Gender": answers[1],
101
+ "Chief complaint": answers[2],
102
+ "Dental history": answers[3],
103
+ "Clinical Findings": answers[4],
104
+ "Treatment plan": answers[5],
105
+ "Referred to": ""
106
+ }
107
 
108
  # Supabase configuration
109
  supabase: Client = create_client(url, key)
 
116
  return [context] * (len(oral_health_assessment_form) - 2) # Adjust for the number of fields
117
 
118
  answers = fill_textboxes(context)
119
+ answers_list = [doctor_name, location] + [""] # Initial patient name field empty
120
+ answers_list += [answers.get(field, "") for field in form_fields[:-1]] # Exclude "Referred to"
121
+ answers_list.append("") # Placeholder for "Referred to"
122
 
123
+ return answers_list
124
 
125
  def save_answers(doctor_name, location, patient_name, age, gender, chief_complaint, medical_history, dental_history, clinical_findings, treatment_plan, referred_to):
126
  current_datetime = datetime.now().isoformat()
 
226
  return [context] * (len(oral_health_assessment_form) - 3) # Adjust for the number of fields
227
 
228
  answers = fill_textboxes(context)
229
+ answers_list = [doctor_name, location] + [""] # Initial patient name field empty
230
+ answers_list += [answers.get(field, "") for field in form_fields[:-1]] # Exclude "Referred to"
231
+ answers_list.append("") # Placeholder for "Referred to"
232
 
233
+ return answers_list
234
 
235
+ transcribe_button.click(fn=update_textboxes, inputs=[audio_input, doctor_name_input, location_input], outputs=[doctor_name_display, location_display] + [patient_name_input] + textboxes_left + textboxes_right + [dropdown_referred])
236
  submit_button = gr.Button("Submit", elem_id="submit_button")
237
+ result_output = gr.HTML(label="Submission Result")
238
+
239
+ def handle_submission(patient_name, age, gender, chief_complaint, dental_history, clinical_findings, treatment_plan, referred_to):
240
+ return save_answers(doctor_name_input.value, location_input.value, patient_name, age, gender, chief_complaint, "none", dental_history, clinical_findings, treatment_plan, referred_to)
241
+
242
+ submit_button.click(fn=handle_submission, inputs=[patient_name_input] + textboxes_left + textboxes_right + [dropdown_referred], outputs=result_output)
243
 
244
+ # Third tab for Download
245
  with gr.Tab("Download CSV"):
246
+ download_button = gr.Button("Download Data as CSV")
247
+ download_output = gr.File(label="Download CSV")
248
+
249
+ download_button.click(fn=gradio_download, outputs=download_output)
250
 
251
+ # Run the Gradio app
252
  demo.launch()