syafiqq02 commited on
Commit
a9f7bba
·
1 Parent(s): af1a275
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. app/main.py +106 -0
  3. app/requirements.txt +10 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /code
4
+
5
+ COPY app /code/app
6
+
7
+ RUN pip install --upgrade pip
8
+ RUN pip install -r /code/app/requirements.txt
9
+
10
+ EXPOSE 8000
11
+
12
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
app/main.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import nltk
3
+ import uvicorn
4
+ from fastapi import FastAPI, File, UploadFile
5
+ from pydantic import BaseModel
6
+ from groq import Groq
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
12
+ groq_client = Groq(api_key=GROQ_API_KEY)
13
+
14
+ def transcribe_audio(audio_path: str):
15
+ with open(audio_path, "rb") as audio_file:
16
+ response = groq_client.audio.transcriptions.create(
17
+ model="whisper-large-v3",
18
+ file=audio_file,
19
+ response_format="text"
20
+ )
21
+ return response
22
+
23
+ def summarize_soap(dialogue: str):
24
+ prompt_soap = f"""
25
+ Anda adalah asisten medis yang membantu dokter dalam menyusun catatan SOAP berdasarkan percakapan dokter dan pasien.
26
+ Ringkaskan dalam bentuk paragraf tanpa bullet point dan gunakan bahasa Indonesia.
27
+ Harap buat ringkasan dalam format berikut:
28
+ Subjective:
29
+ Objective:
30
+ Assessment:
31
+ Plan:
32
+ ### Percakapan:
33
+ {dialogue}
34
+ Tolong jangan tambahkan informasi tambahan selain yang berkaitan dengan diagnosis, obat, hasil lab, dan radiologi.
35
+ """
36
+ response_soap = groq_client.chat.completions.create(
37
+ model="llama3-8b-8192",
38
+ messages=[{"role": "user", "content": prompt_soap}]
39
+ )
40
+ return response_soap.choices[0].message.content
41
+
42
+ def detect_medical_tags(dialogue: str):
43
+ prompt_tags = f"""
44
+ Identifikasi dan berikan luaran dalam bahasa Indonesia tags berikut dari percakapan dengan format:
45
+ Diagnosis:
46
+ Obat:
47
+ Hasil Lab:
48
+ Radiologi:
49
+ ### Percakapan:
50
+ {dialogue}
51
+ Tolong jangan tambahkan informasi tambahan selain yang berkaitan dengan diagnosis, obat, hasil lab, dan radiologi.
52
+ """
53
+ response_tags = groq_client.chat.completions.create(
54
+ model="llama3-8b-8192",
55
+ messages=[{"role": "user", "content": prompt_tags}]
56
+ )
57
+ return response_tags.choices[0].message.content
58
+
59
+ app = FastAPI(title="Medical Transcription Pipeline (Groq API)")
60
+
61
+ @app.get("/")
62
+ async def root():
63
+ return {
64
+ "message": "🚀 SOAP AI FastAPI is running. Use /full_process or /soap_tags to interact"
65
+ }
66
+
67
+ @app.post("/full_process")
68
+ async def full_process(audio: UploadFile = File(...)):
69
+ try:
70
+ filename = audio.filename
71
+ temp_audio_path = f"/tmp/temp_{filename}"
72
+ with open(temp_audio_path, "wb") as f:
73
+ f.write(await audio.read())
74
+
75
+ transcription = transcribe_audio(temp_audio_path)
76
+
77
+ soap_content = summarize_soap(transcription)
78
+ tags_content = detect_medical_tags(transcription)
79
+
80
+ os.remove(temp_audio_path)
81
+
82
+ return {
83
+ "transcription": transcription,
84
+ "soap_content": soap_content,
85
+ "tags_content": tags_content
86
+ }
87
+ except Exception as e:
88
+ return {"error": str(e)}
89
+
90
+ class TranscriptionInput(BaseModel):
91
+ dialogue: str
92
+
93
+ @app.post("/soap_tags")
94
+ async def soap_tags(data: TranscriptionInput):
95
+ transcript_text = data.dialogue
96
+
97
+ soap_content = summarize_soap(transcript_text)
98
+ tags_content = detect_medical_tags(transcript_text)
99
+
100
+ return {
101
+ "soap_content": soap_content,
102
+ "tags_content": tags_content
103
+ }
104
+
105
+ if __name__ == "__main__":
106
+ uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
app/requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.115.8
2
+ faster_whisper==1.1.1
3
+ huggingface_hub==0.28.1
4
+ soundfile==0.13.1
5
+ sumy==0.11.0
6
+ nltk==3.9.1
7
+ uvicorn==0.34.0
8
+ groq==0.18.0
9
+ python-multipart
10
+ python-dotenv