Spaces:
Build error
Build error
Commit Β·
ec31743
1
Parent(s): 4cee811
simplify UI
Browse files
app.py
CHANGED
|
@@ -21,8 +21,7 @@ def chat_with_groq(message):
|
|
| 21 |
messages=[
|
| 22 |
{
|
| 23 |
"role": "system",
|
| 24 |
-
"content": """Anda adalah asisten medis yang membantu dokter dalam menyusun catatan
|
| 25 |
-
Ringkaskan dalam bentuk paragraf tanpa adanya bullet point dan gunakan bahasa Indonesia.""",
|
| 26 |
},
|
| 27 |
{"role": "user", "content": message},
|
| 28 |
],
|
|
@@ -39,7 +38,7 @@ def save_to_file(content, filename):
|
|
| 39 |
|
| 40 |
|
| 41 |
def transcribe_audio(audio_file):
|
| 42 |
-
"""Transkripsi audio menggunakan
|
| 43 |
# segments, _ = model.transcribe(audio_file)
|
| 44 |
# raw_transcription = " ".join(segment.text for segment in segments)
|
| 45 |
with open(audio_file, "rb") as file:
|
|
@@ -50,33 +49,36 @@ def transcribe_audio(audio_file):
|
|
| 50 |
)
|
| 51 |
print(res)
|
| 52 |
raw_transcription = res.text
|
|
|
|
|
|
|
| 53 |
return (
|
| 54 |
-
raw_transcription,
|
| 55 |
-
save_to_file(raw_transcription, "transcription_large.txt"),
|
| 56 |
audio_file,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
|
| 60 |
-
def generate_soap_summary(transcription_text
|
| 61 |
-
"""
|
| 62 |
-
template = """Harap buat ringkasan dalam format berikut:
|
| 63 |
|
| 64 |
Subjective:
|
| 65 |
ICD10:
|
| 66 |
Objective:
|
| 67 |
Assessment:
|
| 68 |
Plan:
|
|
|
|
| 69 |
### Percakapan:
|
| 70 |
{dialogue}
|
| 71 |
-
|
| 72 |
-
### Catatan SOAP:
|
| 73 |
"""
|
| 74 |
|
| 75 |
soap = chat_with_groq(template.format(dialogue=transcription_text))
|
| 76 |
return soap, save_to_file(soap, "soap_summary.txt")
|
| 77 |
|
| 78 |
|
| 79 |
-
def detect_medical_tags(transcription_text
|
| 80 |
"""Mendeteksi tags Diagnosis, Obat, Hasil Lab, dan Radiologi menggunakan model yang dipilih."""
|
| 81 |
template = """
|
| 82 |
Identifikasi dan berikan saran dalam bahasa Indonesia tindakan logis selanjutnya dalam format:
|
|
@@ -94,24 +96,16 @@ def detect_medical_tags(transcription_text, selected_model):
|
|
| 94 |
|
| 95 |
# Antarmuka Gradio
|
| 96 |
with gr.Blocks(
|
| 97 |
-
title="AI-based Medical SOAP Summarization and Tag Detection with
|
| 98 |
) as app:
|
| 99 |
-
gr.Markdown(
|
| 100 |
-
"## Medical SOAP Summarization and Tag Detection with Faster Whisper Large"
|
| 101 |
-
)
|
| 102 |
|
| 103 |
with gr.Row():
|
| 104 |
with gr.Column():
|
| 105 |
-
audio_input = gr.Audio(
|
| 106 |
-
|
| 107 |
-
soap_button = gr.Button("π Buat SOAP")
|
| 108 |
-
tags_button = gr.Button("π·οΈ Deteksi Saran Tags")
|
| 109 |
-
transcription_edit_box = gr.Textbox(
|
| 110 |
-
label="π Hasil Transkripsi (Faster Whisper Large) - Bisa Diedit",
|
| 111 |
-
lines=3,
|
| 112 |
-
interactive=True,
|
| 113 |
)
|
| 114 |
-
|
| 115 |
|
| 116 |
with gr.Column():
|
| 117 |
soap_output = gr.Textbox(label="π Hasil SOAP", lines=10, interactive=False)
|
|
@@ -129,28 +123,14 @@ with gr.Blocks(
|
|
| 129 |
transcribe_button.click(
|
| 130 |
transcribe_audio,
|
| 131 |
inputs=[audio_input],
|
| 132 |
-
outputs=[
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
)
|
| 141 |
-
|
| 142 |
-
# Tombol SOAP
|
| 143 |
-
soap_button.click(
|
| 144 |
-
generate_soap_summary,
|
| 145 |
-
inputs=[transcription_edit_box],
|
| 146 |
-
outputs=[soap_output, download_soap],
|
| 147 |
-
)
|
| 148 |
-
|
| 149 |
-
# Tombol Tags
|
| 150 |
-
tags_button.click(
|
| 151 |
-
detect_medical_tags,
|
| 152 |
-
inputs=[transcription_edit_box],
|
| 153 |
-
outputs=[tags_output, download_tags],
|
| 154 |
)
|
| 155 |
|
| 156 |
# Jalankan aplikasi
|
|
|
|
| 21 |
messages=[
|
| 22 |
{
|
| 23 |
"role": "system",
|
| 24 |
+
"content": """Anda adalah asisten medis yang membantu dokter dalam menyusun catatan medis dalam bentuk paragraf menggunakan bahasa Indonesia.""",
|
|
|
|
| 25 |
},
|
| 26 |
{"role": "user", "content": message},
|
| 27 |
],
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def transcribe_audio(audio_file):
|
| 41 |
+
"""Transkripsi audio menggunakan Whisper tanpa koreksi model Hugging Face."""
|
| 42 |
# segments, _ = model.transcribe(audio_file)
|
| 43 |
# raw_transcription = " ".join(segment.text for segment in segments)
|
| 44 |
with open(audio_file, "rb") as file:
|
|
|
|
| 49 |
)
|
| 50 |
print(res)
|
| 51 |
raw_transcription = res.text
|
| 52 |
+
soap_output, download_soap = generate_soap_summary(raw_transcription)
|
| 53 |
+
tags_output, download_tags = detect_medical_tags(raw_transcription)
|
| 54 |
return (
|
| 55 |
+
save_to_file(raw_transcription, "raw_transcription.txt"),
|
|
|
|
| 56 |
audio_file,
|
| 57 |
+
soap_output,
|
| 58 |
+
download_soap,
|
| 59 |
+
tags_output,
|
| 60 |
+
download_tags,
|
| 61 |
)
|
| 62 |
|
| 63 |
|
| 64 |
+
def generate_soap_summary(transcription_text):
|
| 65 |
+
template = """Buat ringkasan SOAP berdasarkan percakapan dokter dan pasien dalam format berikut:
|
|
|
|
| 66 |
|
| 67 |
Subjective:
|
| 68 |
ICD10:
|
| 69 |
Objective:
|
| 70 |
Assessment:
|
| 71 |
Plan:
|
| 72 |
+
|
| 73 |
### Percakapan:
|
| 74 |
{dialogue}
|
|
|
|
|
|
|
| 75 |
"""
|
| 76 |
|
| 77 |
soap = chat_with_groq(template.format(dialogue=transcription_text))
|
| 78 |
return soap, save_to_file(soap, "soap_summary.txt")
|
| 79 |
|
| 80 |
|
| 81 |
+
def detect_medical_tags(transcription_text):
|
| 82 |
"""Mendeteksi tags Diagnosis, Obat, Hasil Lab, dan Radiologi menggunakan model yang dipilih."""
|
| 83 |
template = """
|
| 84 |
Identifikasi dan berikan saran dalam bahasa Indonesia tindakan logis selanjutnya dalam format:
|
|
|
|
| 96 |
|
| 97 |
# Antarmuka Gradio
|
| 98 |
with gr.Blocks(
|
| 99 |
+
title="AI-based Medical SOAP Summarization and Tag Detection with Whisper Large"
|
| 100 |
) as app:
|
| 101 |
+
gr.Markdown("## Medical SOAP Summarization and Tag Detection with Whisper Large")
|
|
|
|
|
|
|
| 102 |
|
| 103 |
with gr.Row():
|
| 104 |
with gr.Column():
|
| 105 |
+
audio_input = gr.Audio(
|
| 106 |
+
source="microphone", type="filepath", label="ποΈ Rekam Suara"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
)
|
| 108 |
+
transcribe_button = gr.Button("π§ Tulis Rekam Medis")
|
| 109 |
|
| 110 |
with gr.Column():
|
| 111 |
soap_output = gr.Textbox(label="π Hasil SOAP", lines=10, interactive=False)
|
|
|
|
| 123 |
transcribe_button.click(
|
| 124 |
transcribe_audio,
|
| 125 |
inputs=[audio_input],
|
| 126 |
+
outputs=[
|
| 127 |
+
download_transcription,
|
| 128 |
+
download_audio,
|
| 129 |
+
soap_output,
|
| 130 |
+
download_soap,
|
| 131 |
+
tags_output,
|
| 132 |
+
download_tags,
|
| 133 |
+
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
)
|
| 135 |
|
| 136 |
# Jalankan aplikasi
|