farhananis005 commited on
Commit
e0f8e25
·
verified ·
1 Parent(s): 4aa624c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -9
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import shutil
3
  import openai
@@ -163,6 +164,19 @@ def assemblyai_STT(audio_url: str) -> str:
163
 
164
  return transcription_output
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  def generate_report(input_text: str = None, file_path: str = None) -> AI_Medical_Report:
167
  """
168
  Generates a SOAP report from text or audio input using OpenAI's GPT-4 model.
@@ -230,7 +244,7 @@ def generate_report(input_text: str = None, file_path: str = None) -> AI_Medical
230
  return None
231
 
232
  # driver function for making reports
233
- def report_main(input_text: str = None, audio_file: str = None, transcription_service: str = "OpenAI") -> tuple:
234
  """
235
  Generates a SOAP and SBAR report based on user input, either from text or audio.
236
 
@@ -263,11 +277,11 @@ def report_main(input_text: str = None, audio_file: str = None, transcription_se
263
  if transcription_service == "AssemblyAI":
264
  transcription_text = assemblyai_STT(audio_file)
265
  report = generate_report(input_text=transcription_text)
266
- print(transcription_text)
267
  elif transcription_service == "OpenAI":
268
- report = generate_report(file_path=audio_file)
269
- transcription_text = "OpenAI directly accepts Audio Inputs"
270
- print(transcription_text)
271
  else:
272
  raise ValueError("Invalid transcription service specified. Choose 'AssemblyAI' or 'OpenAI'.")
273
  print(report)
@@ -281,9 +295,18 @@ def report_main(input_text: str = None, audio_file: str = None, transcription_se
281
  sbar_report = report.sbar_report
282
  doctor_recommendations = report.recommendations_for_doc
283
  # Return structured output in a tuple
284
- return patient_name, soap_report, sbar_report, doctor_recommendations
 
 
 
 
 
 
 
285
 
286
- # x=generate_report(file_path="/content/Cough.wav")
 
 
287
 
288
  def delete_dir(dir):
289
  try:
@@ -711,7 +734,8 @@ with gr.Blocks(css=css) as demo:
711
  audio_patient_name_box,
712
  audio_soap_report_box,
713
  audio_sbar_report_box,
714
- audio_doctor_recommendations_box
 
715
  ]
716
  )
717
 
@@ -871,4 +895,5 @@ with gr.Blocks(css=css) as demo:
871
  docs2_search_button.click(search2_docs, inputs=[docs2_prompt_input, docs2_search_input, docs2_state], outputs=[docs2_chatbot, docs2_state])
872
  docs2_delete_button.click(delete2_docs, inputs=None, outputs=docs2_delete_output)
873
 
874
- demo.launch(debug=True)
 
 
1
+
2
  import os
3
  import shutil
4
  import openai
 
164
 
165
  return transcription_output
166
 
167
+ def openai_STT(audio_url: str) -> str:
168
+ from openai import OpenAI
169
+ client = OpenAI()
170
+ audio = open(audio_url, "rb")
171
+ transcript = client.audio.transcriptions.create(
172
+ model="whisper-1",
173
+ file=audio,
174
+ response_format="text"
175
+ )
176
+ output = transcript
177
+
178
+ return output
179
+
180
  def generate_report(input_text: str = None, file_path: str = None) -> AI_Medical_Report:
181
  """
182
  Generates a SOAP report from text or audio input using OpenAI's GPT-4 model.
 
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
  """
249
  Generates a SOAP and SBAR report based on user input, either from text or audio.
250
 
 
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:
286
  raise ValueError("Invalid transcription service specified. Choose 'AssemblyAI' or 'OpenAI'.")
287
  print(report)
 
295
  sbar_report = report.sbar_report
296
  doctor_recommendations = report.recommendations_for_doc
297
  # Return structured output in a tuple
298
+ if audio_file:
299
+ return patient_name, soap_report, sbar_report, doctor_recommendations, transcription_text
300
+ else:
301
+ return patient_name, soap_report, sbar_report, doctor_recommendations
302
+
303
+ # x=report_main(audio_file="/content/Cough.wav")
304
+
305
+ # x
306
 
307
+ # y=report_main(input_text="I have fever")
308
+
309
+ # y
310
 
311
  def delete_dir(dir):
312
  try:
 
734
  audio_patient_name_box,
735
  audio_soap_report_box,
736
  audio_sbar_report_box,
737
+ audio_doctor_recommendations_box,
738
+ # audio_transcription_box
739
  ]
740
  )
741
 
 
895
  docs2_search_button.click(search2_docs, inputs=[docs2_prompt_input, docs2_search_input, docs2_state], outputs=[docs2_chatbot, docs2_state])
896
  docs2_delete_button.click(delete2_docs, inputs=None, outputs=docs2_delete_output)
897
 
898
+ demo.launch(debug=True)
899
+