Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,9 +26,7 @@ questions = [
|
|
| 26 |
"What treatment plan do you recommend? Choose only from Options: (Scaling, Filling, Pulp therapy/RCT, Extraction, Medication, Referral) and nothing else"
|
| 27 |
]
|
| 28 |
|
| 29 |
-
|
| 30 |
oral_health_assessment_form = [
|
| 31 |
-
"Doctor’s Name",
|
| 32 |
"Patient’s Name",
|
| 33 |
"Age",
|
| 34 |
"Gender",
|
|
@@ -90,21 +88,24 @@ def fill_textboxes(context):
|
|
| 90 |
supabase: Client = create_client(url, key)
|
| 91 |
|
| 92 |
# Main Gradio app function
|
| 93 |
-
def main(audio):
|
| 94 |
context = transcribe_audio(audio)
|
| 95 |
|
| 96 |
if "Error" in context:
|
| 97 |
-
return [context] * (len(oral_health_assessment_form)
|
| 98 |
|
| 99 |
answers = fill_textboxes(context)
|
| 100 |
-
answers.insert(0, "") # for "
|
| 101 |
-
answers.
|
|
|
|
| 102 |
|
| 103 |
return answers
|
| 104 |
|
| 105 |
def save_answers(*args):
|
| 106 |
current_datetime = datetime.now().isoformat()
|
| 107 |
answers_dict = {oral_health_assessment_form[i]: args[i] for i in range(len(oral_health_assessment_form))}
|
|
|
|
|
|
|
| 108 |
answers_dict["Submission Date and Time"] = current_datetime
|
| 109 |
print("Saved answers:", answers_dict)
|
| 110 |
|
|
@@ -158,25 +159,32 @@ def gradio_download():
|
|
| 158 |
# Create the Gradio interface
|
| 159 |
with gr.Blocks() as demo:
|
| 160 |
gr.Markdown("# OHA Form Filler App")
|
| 161 |
-
audio_input = gr.Audio(type="filepath", label="Record your audio", elem_id="audio_input")
|
| 162 |
-
transcribe_button = gr.Button("Transcribe and Generate Form", elem_id="transcribe_button")
|
| 163 |
|
| 164 |
-
with gr.
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
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)]
|
| 169 |
-
dropdown_referred = gr.Dropdown(choices=["NONE","ORAL MEDICINE & RADIOLOGY", "PERIODONTICS", "ORAL SURGERY", "CONSERVATIVE AND ENDODONTICS", "PROSTHODONTICS", "PEDODONTICS", "ORTHODONTICS"], label="Referred to", interactive=True)
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
download_button.click(fn=gradio_download, inputs=[], outputs=download_csv_output)
|
| 181 |
|
| 182 |
# Launch the app
|
|
|
|
| 26 |
"What treatment plan do you recommend? Choose only from Options: (Scaling, Filling, Pulp therapy/RCT, Extraction, Medication, Referral) and nothing else"
|
| 27 |
]
|
| 28 |
|
|
|
|
| 29 |
oral_health_assessment_form = [
|
|
|
|
| 30 |
"Patient’s Name",
|
| 31 |
"Age",
|
| 32 |
"Gender",
|
|
|
|
| 88 |
supabase: Client = create_client(url, key)
|
| 89 |
|
| 90 |
# Main Gradio app function
|
| 91 |
+
def main(audio, doctor_name, location):
|
| 92 |
context = transcribe_audio(audio)
|
| 93 |
|
| 94 |
if "Error" in context:
|
| 95 |
+
return [context] * (len(oral_health_assessment_form) + 1)
|
| 96 |
|
| 97 |
answers = fill_textboxes(context)
|
| 98 |
+
answers.insert(0, "") # for "Patient’s Name"
|
| 99 |
+
answers.append("") # for "Referred to"
|
| 100 |
+
answers.extend([doctor_name, location])
|
| 101 |
|
| 102 |
return answers
|
| 103 |
|
| 104 |
def save_answers(*args):
|
| 105 |
current_datetime = datetime.now().isoformat()
|
| 106 |
answers_dict = {oral_health_assessment_form[i]: args[i] for i in range(len(oral_health_assessment_form))}
|
| 107 |
+
answers_dict["Doctor’s Name"] = args[-2]
|
| 108 |
+
answers_dict["Location"] = args[-1]
|
| 109 |
answers_dict["Submission Date and Time"] = current_datetime
|
| 110 |
print("Saved answers:", answers_dict)
|
| 111 |
|
|
|
|
| 159 |
# Create the Gradio interface
|
| 160 |
with gr.Blocks() as demo:
|
| 161 |
gr.Markdown("# OHA Form Filler App")
|
|
|
|
|
|
|
| 162 |
|
| 163 |
+
with gr.Page():
|
| 164 |
+
doctor_name = gr.Textbox(label="Doctor’s Name", value="Dr. Alvi", interactive=True)
|
| 165 |
+
location = gr.Textbox(label="Location", value="", interactive=True)
|
| 166 |
+
next_button = gr.Button("Next")
|
|
|
|
|
|
|
| 167 |
|
| 168 |
+
with gr.Page() as main_page:
|
| 169 |
+
audio_input = gr.Audio(type="filepath", label="Record your audio", elem_id="audio_input")
|
| 170 |
+
transcribe_button = gr.Button("Transcribe and Generate Form", elem_id="transcribe_button")
|
| 171 |
+
|
| 172 |
+
with gr.Row(elem_id="textboxes_row"):
|
| 173 |
+
with gr.Column():
|
| 174 |
+
textboxes_left = [gr.Textbox(label=oral_health_assessment_form[i], value="", interactive=True) for i in range(0, len(oral_health_assessment_form)//2)]
|
| 175 |
+
with gr.Column():
|
| 176 |
+
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)]
|
| 177 |
+
dropdown_referred = gr.Dropdown(choices=["NONE","ORAL MEDICINE & RADIOLOGY", "PERIODONTICS", "ORAL SURGERY", "CONSERVATIVE AND ENDODONTICS", "PROSTHODONTICS", "PEDODONTICS", "ORTHODONTICS"], label="Referred to", interactive=True)
|
| 178 |
+
|
| 179 |
+
submit_button = gr.Button("Submit", elem_id="submit_button")
|
| 180 |
+
output_html = gr.HTML(label="Submitted Answers")
|
| 181 |
+
|
| 182 |
+
download_button = gr.Button("Download Table as CSV")
|
| 183 |
+
download_csv_output = gr.File(label="Download CSV")
|
| 184 |
+
|
| 185 |
+
next_button.click(fn=None, inputs=[doctor_name, location], outputs=main_page)
|
| 186 |
+
transcribe_button.click(fn=main, inputs=[audio_input, doctor_name, location], outputs=textboxes_left + textboxes_right + [dropdown_referred])
|
| 187 |
+
submit_button.click(fn=save_answers, inputs=textboxes_left + textboxes_right + [dropdown_referred, doctor_name, location], outputs=output_html)
|
| 188 |
download_button.click(fn=gradio_download, inputs=[], outputs=download_csv_output)
|
| 189 |
|
| 190 |
# Launch the app
|