Update app.py
Browse files
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
|
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 |
-
|
44 |
-
|
|
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
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=
|
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()
|