farhananis005 commited on
Commit
45e2cbf
·
verified ·
1 Parent(s): 716aab8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import os
3
  import shutil
4
  import openai
@@ -243,6 +242,10 @@ def generate_report(input_text: str = None, file_path: str = None) -> AI_Medical
243
  print(f"An error occurred: {e}")
244
  return None
245
 
 
 
 
 
246
  # driver function for making reports
247
  def report_main(input_text: str = None, audio_file: str = None, transcription_service: str = "OpenAI"):
248
  """
@@ -275,11 +278,11 @@ def report_main(input_text: str = None, audio_file: str = None, transcription_se
275
  elif audio_file:
276
  # Use selected transcription service for audio input
277
  if transcription_service == "AssemblyAI":
278
- transcription_text = assemblyai_STT(audio_file)
279
  report = generate_report(input_text=transcription_text)
280
  # print(transcription_text)
281
  elif transcription_service == "OpenAI":
282
- transcription_text = openai_STT(audio_file)
283
  report = generate_report(input_text=transcription_text)
284
  # print(transcription_text)
285
  else:
@@ -290,7 +293,6 @@ def report_main(input_text: str = None, audio_file: str = None, transcription_se
290
  else:
291
  raise ValueError("Either input_text or audio_file must be provided.")
292
 
293
- # patient_name = report
294
  patient_name = report.patient_name
295
  soap_report = report.soap_report
296
  sbar_report = report.sbar_report
@@ -301,14 +303,6 @@ def report_main(input_text: str = None, audio_file: str = None, transcription_se
301
  else:
302
  return patient_name, soap_report, sbar_report, doctor_recommendations
303
 
304
- # x=report_main(audio_file="/content/Cough.wav")
305
-
306
- # x
307
-
308
- y=report_main(input_text="I have fever")
309
-
310
- print(y)
311
-
312
  def delete_dir(dir):
313
  try:
314
  shutil.rmtree(dir)
@@ -725,18 +719,18 @@ with gr.Blocks(css=css) as demo:
725
  audio_sbar_report_box = gr.Textbox(label="SBAR Report", interactive=True, placeholder="Generated SBAR Report", lines=10)
726
 
727
  audio_doctor_recommendations_box = gr.Textbox(label="Doctor Recommendations", interactive=False, placeholder="Recommendations", lines=5)
728
- # audio_transcription_box = gr.Textbox(label="Transcription Text", interactive=False, placeholder="Transcribed Text", lines=5)
729
 
730
  # Click event for audio
731
  generate_with_audio_button.click(
732
- fn=report_main,
733
  inputs=[audio_file, transcription_service],
734
  outputs=[
735
  audio_patient_name_box,
736
  audio_soap_report_box,
737
  audio_sbar_report_box,
738
  audio_doctor_recommendations_box,
739
- # audio_transcription_box
740
  ]
741
  )
742
 
@@ -897,4 +891,3 @@ with gr.Blocks(css=css) as demo:
897
  docs2_delete_button.click(delete2_docs, inputs=None, outputs=docs2_delete_output)
898
 
899
  demo.launch(debug=True)
900
-
 
 
1
  import os
2
  import shutil
3
  import openai
 
242
  print(f"An error occurred: {e}")
243
  return None
244
 
245
+ # wrapper function for audio
246
+ def report_audio(audio_file: str = None, transcription_service: str = "OpenAI"):
247
+ return report_main(audio_file=audio_file,transcription_service=transcription_service)
248
+
249
  # driver function for making reports
250
  def report_main(input_text: str = None, audio_file: str = None, transcription_service: str = "OpenAI"):
251
  """
 
278
  elif audio_file:
279
  # Use selected transcription service for audio input
280
  if transcription_service == "AssemblyAI":
281
+ transcription_text += assemblyai_STT(audio_file)
282
  report = generate_report(input_text=transcription_text)
283
  # print(transcription_text)
284
  elif transcription_service == "OpenAI":
285
+ transcription_text += openai_STT(audio_file)
286
  report = generate_report(input_text=transcription_text)
287
  # print(transcription_text)
288
  else:
 
293
  else:
294
  raise ValueError("Either input_text or audio_file must be provided.")
295
 
 
296
  patient_name = report.patient_name
297
  soap_report = report.soap_report
298
  sbar_report = report.sbar_report
 
303
  else:
304
  return patient_name, soap_report, sbar_report, doctor_recommendations
305
 
 
 
 
 
 
 
 
 
306
  def delete_dir(dir):
307
  try:
308
  shutil.rmtree(dir)
 
719
  audio_sbar_report_box = gr.Textbox(label="SBAR Report", interactive=True, placeholder="Generated SBAR Report", lines=10)
720
 
721
  audio_doctor_recommendations_box = gr.Textbox(label="Doctor Recommendations", interactive=False, placeholder="Recommendations", lines=5)
722
+ audio_transcription_box = gr.Textbox(label="Transcription Text", interactive=False, placeholder="Transcribed Text", lines=5)
723
 
724
  # Click event for audio
725
  generate_with_audio_button.click(
726
+ fn=report_audio,
727
  inputs=[audio_file, transcription_service],
728
  outputs=[
729
  audio_patient_name_box,
730
  audio_soap_report_box,
731
  audio_sbar_report_box,
732
  audio_doctor_recommendations_box,
733
+ audio_transcription_box
734
  ]
735
  )
736
 
 
891
  docs2_delete_button.click(delete2_docs, inputs=None, outputs=docs2_delete_output)
892
 
893
  demo.launch(debug=True)