chrisaldikaraharja commited on
Commit
866ef54
·
verified ·
1 Parent(s): c4de38f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -6,7 +6,7 @@ from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
6
  tokenizer = AutoTokenizer.from_pretrained("deepset/roberta-base-squad2")
7
  model = AutoModelForQuestionAnswering.from_pretrained("deepset/roberta-base-squad2")
8
 
9
- # Load a faster speech-to-text model
10
  s2t = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
11
 
12
  # Function to extract structured information using question answering
@@ -40,23 +40,29 @@ def extract_structured_info(note):
40
  return answers
41
 
42
  def process_audio(audio):
43
- if audio is None:
44
- return "No audio provided", "N/A", "N/A", "N/A", "N/A"
 
45
 
46
- # Transcribe audio to text
47
- transcription_result = s2t(audio)
48
- transcription = transcription_result.get("text", "")
49
 
50
- # Extract structured information
51
- structured_info = extract_structured_info(transcription)
52
 
53
- return (
54
- transcription,
55
- structured_info["Patient Name"],
56
- structured_info["Age"],
57
- structured_info["Medical History"],
58
- structured_info["Physical Examination"]
59
- )
 
 
 
 
 
60
 
61
  # Set up Gradio Interface with structured outputs
62
  iface = gr.Interface(
@@ -71,7 +77,6 @@ iface = gr.Interface(
71
  gr.Textbox(label="Medical History"),
72
  gr.Textbox(label="Physical Examination"),
73
  ],
74
- live=False # Disable live updates for faster response
75
  )
76
-
77
  iface.launch()
 
6
  tokenizer = AutoTokenizer.from_pretrained("deepset/roberta-base-squad2")
7
  model = AutoModelForQuestionAnswering.from_pretrained("deepset/roberta-base-squad2")
8
 
9
+ # Load the speech-to-text model
10
  s2t = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
11
 
12
  # Function to extract structured information using question answering
 
40
  return answers
41
 
42
  def process_audio(audio):
43
+ try:
44
+ if audio is None:
45
+ return "No audio provided", "N/A", "N/A", "N/A", "N/A"
46
 
47
+ # Transcribe audio to text
48
+ transcription_result = s2t(audio)
49
+ transcription = transcription_result.get("text", "")
50
 
51
+ # Extract structured information
52
+ structured_info = extract_structured_info(transcription)
53
 
54
+ return (
55
+ transcription,
56
+ structured_info["Patient Name"],
57
+ structured_info["Age"],
58
+ structured_info["Medical History"],
59
+ structured_info["Physical Examination"]
60
+ )
61
+
62
+ except Exception as e:
63
+ # Capture any errors and display them in output fields
64
+ error_message = f"Error: {str(e)}"
65
+ return error_message, error_message, error_message, error_message, error_message
66
 
67
  # Set up Gradio Interface with structured outputs
68
  iface = gr.Interface(
 
77
  gr.Textbox(label="Medical History"),
78
  gr.Textbox(label="Physical Examination"),
79
  ],
80
+ live=True # Automatically triggers on new input
81
  )
 
82
  iface.launch()