NikilDGr8 commited on
Commit
eeabe0b
·
verified ·
1 Parent(s): 552fbe4

fix: medical history

Browse files
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -5,6 +5,7 @@ import os
5
  from supabase import create_client, Client
6
  from datetime import datetime
7
  import csv
 
8
 
9
  # Add your AssemblyAI API key as Environment Variable
10
  aai.settings.api_key = os.environ['Assembly']
@@ -18,9 +19,10 @@ question_answerer = pipeline("question-answering", model='distilbert-base-cased-
18
  questions = [
19
  "How old is the patient?",
20
  "What is the gender?",
21
- "What is the chief complaint regarding the patient's oral health? If there is none, just say the word 'none' else elaborate",
 
22
  "Can you provide any relevant Dental history for the patient? If there is none, just say the word 'none', else elaborate",
23
- "Give me about the clinical findings listed",
24
  "What treatment plan do you recommend?"
25
  ]
26
 
@@ -52,12 +54,12 @@ oral_health_assessment_form = [
52
  ]
53
 
54
  # Function to generate answers for the questions
55
- def generate_answer(question, context):
56
  result = question_answerer(question=question, context=context)
57
  return result['answer']
58
 
59
  # Function to handle audio recording and transcription
60
- def transcribe_audio(audio_path):
61
  print(f"Received audio file at: {audio_path}")
62
 
63
  # Check if the file exists and is not empty
@@ -89,7 +91,7 @@ def transcribe_audio(audio_path):
89
  return str(e)
90
 
91
  # Function to fill in the answers for the text boxes
92
- def fill_textboxes(context):
93
  answers = []
94
  for question in questions:
95
  answer = generate_answer(question, context)
@@ -100,10 +102,10 @@ def fill_textboxes(context):
100
  "Age": answers[0],
101
  "Gender": answers[1],
102
  "Chief complaint": answers[2],
103
- "Medical history": "none", # Medical history is not part of the questions
104
- "Dental history": answers[3],
105
- "Clinical Findings": answers[4],
106
- "Treatment plan": answers[5],
107
  "Referred to": ""
108
  }
109
 
@@ -111,19 +113,19 @@ def fill_textboxes(context):
111
  supabase: Client = create_client(url, key)
112
 
113
  # Main Gradio app function
114
- def main(audio, doctor_name, location):
115
  context = transcribe_audio(audio)
116
 
117
  if "Error" in context:
118
  return [context] * (len(oral_health_assessment_form) - 2) # Adjust for the number of fields
119
 
120
  answers = fill_textboxes(context)
121
- answers_list = [doctor_name, location] + [""] # Initial patient name field empty
122
  answers_list += [answers.get(field, "") for field in form_fields]
123
 
124
  return answers_list
125
 
126
- def save_answers(doctor_name, location, patient_name, age, gender, chief_complaint, medical_history, dental_history, clinical_findings, treatment_plan, referred_to):
127
  current_datetime = datetime.now().isoformat()
128
  answers_dict = {
129
  "Doctor’s Name": doctor_name,
@@ -151,7 +153,7 @@ def save_answers(doctor_name, location, patient_name, age, gender, chief_complai
151
  return f"Error saving answers: {e}"
152
 
153
  # Function to download table as CSV
154
- def download_table_to_csv():
155
  # Fetch data from Supabase table
156
  response = supabase.table("oral_health_assessments").select("*").execute()
157
 
@@ -182,7 +184,7 @@ def download_table_to_csv():
182
  print("Downloaded table oral_health_assessments")
183
  return csv_file
184
 
185
- def gradio_download():
186
  file_path = download_table_to_csv()
187
  if file_path:
188
  return file_path
@@ -220,19 +222,19 @@ with gr.Blocks() as demo:
220
  textboxes_right = [gr.Textbox(label=oral_health_assessment_form[i], value="", interactive=True) for i in range(len(oral_health_assessment_form)//2, len(oral_health_assessment_form)-1)]
221
  dropdown_referred = gr.Dropdown(choices=["NONE","ORAL MEDICINE & RADIOLOGY", "PERIODONTICS", "ORAL SURGERY", "CONSERVATIVE AND ENDODONTICS", "PROSTHODONTICS", "PEDODONTICS", "ORTHODONTICS"], label="Referred to", interactive=True)
222
 
223
- def enable_transcribe_button(audio_path):
224
  return gr.update(interactive=True)
225
 
226
  audio_input.change(fn=enable_transcribe_button, inputs=audio_input, outputs=transcribe_button)
227
 
228
- def update_textboxes(audio, doctor_name, location):
229
  context = transcribe_audio(audio)
230
 
231
  if "Error" in context:
232
  return [context] * (len(oral_health_assessment_form) - 3) # Adjust for the number of fields
233
 
234
  answers = fill_textboxes(context)
235
- answers_list = [doctor_name, location] + [""] # Initial patient name field empty
236
  answers_list += [answers.get(field, "") for field in form_fields[:-1]] # Exclude "Referred to"
237
  answers_list.append(answers.get("Referred to", "")) # Ensure "Referred to" is included
238
 
@@ -243,7 +245,7 @@ with gr.Blocks() as demo:
243
  save_button = gr.Button("Save Form")
244
  save_output = gr.HTML(label="Save Output")
245
 
246
- def handle_submission(doctor_name, location, patient_name, age, gender, chief_complaint, medical_history, dental_history, clinical_findings, treatment_plan, referred_to):
247
  return save_answers(doctor_name, location, patient_name, age, gender, chief_complaint, medical_history, dental_history, clinical_findings, treatment_plan, referred_to)
248
 
249
  save_button.click(fn=handle_submission, inputs=[doctor_name_display, location_display, patient_name_input] + textboxes_left + textboxes_right + [dropdown_referred], outputs=save_output)
 
5
  from supabase import create_client, Client
6
  from datetime import datetime
7
  import csv
8
+ from typing import Optional
9
 
10
  # Add your AssemblyAI API key as Environment Variable
11
  aai.settings.api_key = os.environ['Assembly']
 
19
  questions = [
20
  "How old is the patient?",
21
  "What is the gender?",
22
+ "What is the chief complaint regarding the patient's oral health?",
23
+ "Can you provide any relevant Medication history for the patient? If there is none, just say the word 'none', else elaborate",
24
  "Can you provide any relevant Dental history for the patient? If there is none, just say the word 'none', else elaborate",
25
+ "Please give all the clinical findings which were listed",
26
  "What treatment plan do you recommend?"
27
  ]
28
 
 
54
  ]
55
 
56
  # Function to generate answers for the questions
57
+ def generate_answer(question: str, context: str) -> str:
58
  result = question_answerer(question=question, context=context)
59
  return result['answer']
60
 
61
  # Function to handle audio recording and transcription
62
+ def transcribe_audio(audio_path: str) -> str:
63
  print(f"Received audio file at: {audio_path}")
64
 
65
  # Check if the file exists and is not empty
 
91
  return str(e)
92
 
93
  # Function to fill in the answers for the text boxes
94
+ def fill_textboxes(context: str) -> dict:
95
  answers = []
96
  for question in questions:
97
  answer = generate_answer(question, context)
 
102
  "Age": answers[0],
103
  "Gender": answers[1],
104
  "Chief complaint": answers[2],
105
+ "Medical history": answers[3],
106
+ "Dental history": answers[4],
107
+ "Clinical Findings": answers[5],
108
+ "Treatment plan": answers[6],
109
  "Referred to": ""
110
  }
111
 
 
113
  supabase: Client = create_client(url, key)
114
 
115
  # Main Gradio app function
116
+ def main(audio: str, doctor_name: str, location: str) -> list:
117
  context = transcribe_audio(audio)
118
 
119
  if "Error" in context:
120
  return [context] * (len(oral_health_assessment_form) - 2) # Adjust for the number of fields
121
 
122
  answers = fill_textboxes(context)
123
+ answers_list = [doctor_name, location, ""] # Initial patient name field empty
124
  answers_list += [answers.get(field, "") for field in form_fields]
125
 
126
  return answers_list
127
 
128
+ def save_answers(doctor_name: str, location: str, patient_name: str, age: str, gender: str, chief_complaint: str, medical_history: str, dental_history: str, clinical_findings: str, treatment_plan: str, referred_to: str) -> str:
129
  current_datetime = datetime.now().isoformat()
130
  answers_dict = {
131
  "Doctor’s Name": doctor_name,
 
153
  return f"Error saving answers: {e}"
154
 
155
  # Function to download table as CSV
156
+ def download_table_to_csv() -> Optional[str]:
157
  # Fetch data from Supabase table
158
  response = supabase.table("oral_health_assessments").select("*").execute()
159
 
 
184
  print("Downloaded table oral_health_assessments")
185
  return csv_file
186
 
187
+ def gradio_download() -> Optional[str]:
188
  file_path = download_table_to_csv()
189
  if file_path:
190
  return file_path
 
222
  textboxes_right = [gr.Textbox(label=oral_health_assessment_form[i], value="", interactive=True) for i in range(len(oral_health_assessment_form)//2, len(oral_health_assessment_form)-1)]
223
  dropdown_referred = gr.Dropdown(choices=["NONE","ORAL MEDICINE & RADIOLOGY", "PERIODONTICS", "ORAL SURGERY", "CONSERVATIVE AND ENDODONTICS", "PROSTHODONTICS", "PEDODONTICS", "ORTHODONTICS"], label="Referred to", interactive=True)
224
 
225
+ def enable_transcribe_button(audio_path: str):
226
  return gr.update(interactive=True)
227
 
228
  audio_input.change(fn=enable_transcribe_button, inputs=audio_input, outputs=transcribe_button)
229
 
230
+ def update_textboxes(audio: str, doctor_name: str, location: str):
231
  context = transcribe_audio(audio)
232
 
233
  if "Error" in context:
234
  return [context] * (len(oral_health_assessment_form) - 3) # Adjust for the number of fields
235
 
236
  answers = fill_textboxes(context)
237
+ answers_list = [doctor_name, location, ""] # Initial patient name field empty
238
  answers_list += [answers.get(field, "") for field in form_fields[:-1]] # Exclude "Referred to"
239
  answers_list.append(answers.get("Referred to", "")) # Ensure "Referred to" is included
240
 
 
245
  save_button = gr.Button("Save Form")
246
  save_output = gr.HTML(label="Save Output")
247
 
248
+ def handle_submission(doctor_name: str, location: str, patient_name: str, age: str, gender: str, chief_complaint: str, medical_history: str, dental_history: str, clinical_findings: str, treatment_plan: str, referred_to: str):
249
  return save_answers(doctor_name, location, patient_name, age, gender, chief_complaint, medical_history, dental_history, clinical_findings, treatment_plan, referred_to)
250
 
251
  save_button.click(fn=handle_submission, inputs=[doctor_name_display, location_display, patient_name_input] + textboxes_left + textboxes_right + [dropdown_referred], outputs=save_output)