Spaces:
Running
Running
gradio file
Browse files
app.py
CHANGED
@@ -17,6 +17,14 @@ huggingface_client = InferenceClient(api_key=HF_API_KEY)
|
|
17 |
# Load Faster Whisper model versi large
|
18 |
model = faster_whisper.WhisperModel("turbo", device="cpu", compute_type="int8")
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def save_to_file(content, filename):
|
21 |
with open(filename, 'w', encoding='utf-8') as file:
|
22 |
file.write(content)
|
@@ -28,8 +36,8 @@ def transcribe_audio(audio_path):
|
|
28 |
raw_transcription = " ".join(segment.text for segment in segments)
|
29 |
return raw_transcription, save_to_file(raw_transcription, 'transcription_large.txt'), audio_path
|
30 |
|
31 |
-
def generate_soap_summary(transcription_text):
|
32 |
-
"""Membuat ringkasan SOAP dari teks transkripsi."""
|
33 |
template = """
|
34 |
Anda adalah asisten medis yang membantu dokter dalam menyusun catatan SOAP berdasarkan percakapan dokter dan pasien.
|
35 |
Ringkaskan dalam bentuk paragraf tanpa adanya bullet point dan gunakan bahasa Indonesia.
|
@@ -47,7 +55,7 @@ def generate_soap_summary(transcription_text):
|
|
47 |
"""
|
48 |
messages = [{"role": "user", "content": template.format(dialogue=transcription_text)}]
|
49 |
response = huggingface_client.chat.completions.create(
|
50 |
-
model=
|
51 |
messages=messages,
|
52 |
max_tokens=1000,
|
53 |
stream=False
|
@@ -55,8 +63,8 @@ def generate_soap_summary(transcription_text):
|
|
55 |
soap = response.choices[0].message.content.strip()
|
56 |
return soap, save_to_file(soap, 'soap_summary.txt')
|
57 |
|
58 |
-
def detect_medical_tags(transcription_text):
|
59 |
-
"""Mendeteksi tags Diagnosis, Obat, Hasil Lab, dan Radiologi."""
|
60 |
template = """
|
61 |
Identifikasi dan berikan luaran dalam bahasa indonesia tags berikut dari percakapan:
|
62 |
Diagnosis:
|
@@ -69,7 +77,7 @@ def detect_medical_tags(transcription_text):
|
|
69 |
"""
|
70 |
messages = [{"role": "user", "content": template.format(dialogue=transcription_text)}]
|
71 |
response = huggingface_client.chat.completions.create(
|
72 |
-
model=
|
73 |
messages=messages,
|
74 |
max_tokens=500,
|
75 |
stream=False
|
@@ -83,6 +91,11 @@ with gr.Blocks(title="AI-based Medical SOAP Summarization and Tag Detection with
|
|
83 |
|
84 |
with gr.Row():
|
85 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
86 |
audio_input = gr.Audio("microphone", type="filepath", label="ποΈ Rekam Suara")
|
87 |
transcribe_button = gr.Button("π§ Transkripsi dengan Whisper Large")
|
88 |
transcription_edit_box = gr.Textbox(label="π Hasil Transkripsi (Faster Whisper Large) - Bisa Diedit", lines=12, interactive=True)
|
@@ -115,14 +128,14 @@ with gr.Blocks(title="AI-based Medical SOAP Summarization and Tag Detection with
|
|
115 |
# Tombol SOAP
|
116 |
soap_button.click(
|
117 |
generate_soap_summary,
|
118 |
-
inputs=[transcription_edit_box],
|
119 |
outputs=[soap_output, download_soap]
|
120 |
)
|
121 |
|
122 |
# Tombol Tags
|
123 |
tags_button.click(
|
124 |
detect_medical_tags,
|
125 |
-
inputs=[transcription_edit_box],
|
126 |
outputs=[tags_output, download_tags]
|
127 |
)
|
128 |
|
|
|
17 |
# Load Faster Whisper model versi large
|
18 |
model = faster_whisper.WhisperModel("turbo", device="cpu", compute_type="int8")
|
19 |
|
20 |
+
# Daftar model yang dapat dipilih
|
21 |
+
MODEL_OPTIONS = [
|
22 |
+
"mistralai/Mistral-7B-Instruct-v0.3",
|
23 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
24 |
+
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
25 |
+
"Qwen/Qwen2.5-Coder-32B-Instruct"
|
26 |
+
]
|
27 |
+
|
28 |
def save_to_file(content, filename):
|
29 |
with open(filename, 'w', encoding='utf-8') as file:
|
30 |
file.write(content)
|
|
|
36 |
raw_transcription = " ".join(segment.text for segment in segments)
|
37 |
return raw_transcription, save_to_file(raw_transcription, 'transcription_large.txt'), audio_path
|
38 |
|
39 |
+
def generate_soap_summary(transcription_text, selected_model):
|
40 |
+
"""Membuat ringkasan SOAP dari teks transkripsi menggunakan model yang dipilih."""
|
41 |
template = """
|
42 |
Anda adalah asisten medis yang membantu dokter dalam menyusun catatan SOAP berdasarkan percakapan dokter dan pasien.
|
43 |
Ringkaskan dalam bentuk paragraf tanpa adanya bullet point dan gunakan bahasa Indonesia.
|
|
|
55 |
"""
|
56 |
messages = [{"role": "user", "content": template.format(dialogue=transcription_text)}]
|
57 |
response = huggingface_client.chat.completions.create(
|
58 |
+
model=selected_model,
|
59 |
messages=messages,
|
60 |
max_tokens=1000,
|
61 |
stream=False
|
|
|
63 |
soap = response.choices[0].message.content.strip()
|
64 |
return soap, save_to_file(soap, 'soap_summary.txt')
|
65 |
|
66 |
+
def detect_medical_tags(transcription_text, selected_model):
|
67 |
+
"""Mendeteksi tags Diagnosis, Obat, Hasil Lab, dan Radiologi menggunakan model yang dipilih."""
|
68 |
template = """
|
69 |
Identifikasi dan berikan luaran dalam bahasa indonesia tags berikut dari percakapan:
|
70 |
Diagnosis:
|
|
|
77 |
"""
|
78 |
messages = [{"role": "user", "content": template.format(dialogue=transcription_text)}]
|
79 |
response = huggingface_client.chat.completions.create(
|
80 |
+
model=selected_model,
|
81 |
messages=messages,
|
82 |
max_tokens=500,
|
83 |
stream=False
|
|
|
91 |
|
92 |
with gr.Row():
|
93 |
with gr.Column():
|
94 |
+
model_selector = gr.Dropdown(
|
95 |
+
choices=MODEL_OPTIONS,
|
96 |
+
value="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
97 |
+
label="π Pilih Model AI"
|
98 |
+
)
|
99 |
audio_input = gr.Audio("microphone", type="filepath", label="ποΈ Rekam Suara")
|
100 |
transcribe_button = gr.Button("π§ Transkripsi dengan Whisper Large")
|
101 |
transcription_edit_box = gr.Textbox(label="π Hasil Transkripsi (Faster Whisper Large) - Bisa Diedit", lines=12, interactive=True)
|
|
|
128 |
# Tombol SOAP
|
129 |
soap_button.click(
|
130 |
generate_soap_summary,
|
131 |
+
inputs=[transcription_edit_box, model_selector],
|
132 |
outputs=[soap_output, download_soap]
|
133 |
)
|
134 |
|
135 |
# Tombol Tags
|
136 |
tags_button.click(
|
137 |
detect_medical_tags,
|
138 |
+
inputs=[transcription_edit_box, model_selector],
|
139 |
outputs=[tags_output, download_tags]
|
140 |
)
|
141 |
|