Spaces:
Runtime error
Runtime error
ya
Browse files- app/__pycache__/main.cpython-39.pyc +0 -0
- app/main.py +27 -30
app/__pycache__/main.cpython-39.pyc
CHANGED
|
Binary files a/app/__pycache__/main.cpython-39.pyc and b/app/__pycache__/main.cpython-39.pyc differ
|
|
|
app/main.py
CHANGED
|
@@ -5,14 +5,14 @@ from fastapi import FastAPI, File, UploadFile
|
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from groq import Groq
|
| 7 |
|
| 8 |
-
|
| 9 |
GROQ_API_KEY = "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"
|
| 10 |
groq_client = Groq(api_key=GROQ_API_KEY)
|
| 11 |
|
| 12 |
def save_to_file(content: str, filename: str) -> str:
|
| 13 |
-
|
|
|
|
| 14 |
file.write(content)
|
| 15 |
-
return
|
| 16 |
|
| 17 |
def transcribe_audio(audio_path: str):
|
| 18 |
with open(audio_path, "rb") as audio_file:
|
|
@@ -21,22 +21,19 @@ def transcribe_audio(audio_path: str):
|
|
| 21 |
file=audio_file,
|
| 22 |
response_format="text"
|
| 23 |
)
|
| 24 |
-
|
| 25 |
-
return transcription
|
| 26 |
|
| 27 |
def summarize_soap(dialogue: str):
|
| 28 |
prompt_soap = f"""
|
| 29 |
Anda adalah asisten medis yang membantu dokter dalam menyusun catatan SOAP berdasarkan percakapan dokter dan pasien.
|
| 30 |
-
Ringkaskan dalam bentuk paragraf tanpa
|
| 31 |
Harap buat ringkasan dalam format berikut:
|
| 32 |
Subjective:
|
| 33 |
Objective:
|
| 34 |
Assessment:
|
| 35 |
Plan:
|
| 36 |
-
|
| 37 |
### Percakapan:
|
| 38 |
{dialogue}
|
| 39 |
-
|
| 40 |
Tolong jangan tambahkan informasi tambahan selain yang berkaitan dengan diagnosis, obat, hasil lab, dan radiologi.
|
| 41 |
"""
|
| 42 |
response_soap = groq_client.chat.completions.create(
|
|
@@ -57,10 +54,8 @@ def detect_medical_tags(dialogue: str):
|
|
| 57 |
Obat:
|
| 58 |
Hasil Lab:
|
| 59 |
Radiologi:
|
| 60 |
-
|
| 61 |
### Percakapan:
|
| 62 |
{dialogue}
|
| 63 |
-
|
| 64 |
Tolong jangan tambahkan informasi tambahan selain yang berkaitan dengan diagnosis, obat, hasil lab, dan radiologi.
|
| 65 |
"""
|
| 66 |
response_tags = groq_client.chat.completions.create(
|
|
@@ -84,26 +79,28 @@ async def root():
|
|
| 84 |
|
| 85 |
@app.post("/full_process")
|
| 86 |
async def full_process(audio: UploadFile = File(...)):
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
| 107 |
|
| 108 |
class TranscriptionInput(BaseModel):
|
| 109 |
dialogue: str
|
|
|
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from groq import Groq
|
| 7 |
|
|
|
|
| 8 |
GROQ_API_KEY = "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"
|
| 9 |
groq_client = Groq(api_key=GROQ_API_KEY)
|
| 10 |
|
| 11 |
def save_to_file(content: str, filename: str) -> str:
|
| 12 |
+
filepath = f"/tmp/{filename}"
|
| 13 |
+
with open(filepath, 'w', encoding='utf-8') as file:
|
| 14 |
file.write(content)
|
| 15 |
+
return filepath
|
| 16 |
|
| 17 |
def transcribe_audio(audio_path: str):
|
| 18 |
with open(audio_path, "rb") as audio_file:
|
|
|
|
| 21 |
file=audio_file,
|
| 22 |
response_format="text"
|
| 23 |
)
|
| 24 |
+
return response
|
|
|
|
| 25 |
|
| 26 |
def summarize_soap(dialogue: str):
|
| 27 |
prompt_soap = f"""
|
| 28 |
Anda adalah asisten medis yang membantu dokter dalam menyusun catatan SOAP berdasarkan percakapan dokter dan pasien.
|
| 29 |
+
Ringkaskan dalam bentuk paragraf tanpa bullet point dan gunakan bahasa Indonesia.
|
| 30 |
Harap buat ringkasan dalam format berikut:
|
| 31 |
Subjective:
|
| 32 |
Objective:
|
| 33 |
Assessment:
|
| 34 |
Plan:
|
|
|
|
| 35 |
### Percakapan:
|
| 36 |
{dialogue}
|
|
|
|
| 37 |
Tolong jangan tambahkan informasi tambahan selain yang berkaitan dengan diagnosis, obat, hasil lab, dan radiologi.
|
| 38 |
"""
|
| 39 |
response_soap = groq_client.chat.completions.create(
|
|
|
|
| 54 |
Obat:
|
| 55 |
Hasil Lab:
|
| 56 |
Radiologi:
|
|
|
|
| 57 |
### Percakapan:
|
| 58 |
{dialogue}
|
|
|
|
| 59 |
Tolong jangan tambahkan informasi tambahan selain yang berkaitan dengan diagnosis, obat, hasil lab, dan radiologi.
|
| 60 |
"""
|
| 61 |
response_tags = groq_client.chat.completions.create(
|
|
|
|
| 79 |
|
| 80 |
@app.post("/full_process")
|
| 81 |
async def full_process(audio: UploadFile = File(...)):
|
| 82 |
+
try:
|
| 83 |
+
filename = audio.filename
|
| 84 |
+
temp_audio_path = f"/tmp/temp_{filename}"
|
| 85 |
+
with open(temp_audio_path, "wb") as f:
|
| 86 |
+
f.write(await audio.read())
|
| 87 |
+
|
| 88 |
+
transcription = transcribe_audio(temp_audio_path)
|
| 89 |
+
|
| 90 |
+
soap_content, soap_file = generate_soap(transcription)
|
| 91 |
+
tags_content, tags_file = generate_tags(transcription)
|
| 92 |
+
|
| 93 |
+
os.remove(temp_audio_path)
|
| 94 |
+
|
| 95 |
+
return {
|
| 96 |
+
"transcription": transcription,
|
| 97 |
+
"soap_content": soap_content,
|
| 98 |
+
"soap_file": soap_file,
|
| 99 |
+
"tags_content": tags_content,
|
| 100 |
+
"tags_file": tags_file
|
| 101 |
+
}
|
| 102 |
+
except Exception as e:
|
| 103 |
+
return {"error": str(e)}
|
| 104 |
|
| 105 |
class TranscriptionInput(BaseModel):
|
| 106 |
dialogue: str
|