Initial commit: Doctor-Patient clinical transcription and structured summary pipeline
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import os, urllib.request, json
|
||||
|
||||
api_key = None
|
||||
with open('.env') as f:
|
||||
for line in f:
|
||||
if line.startswith('SARVAM_API_KEY='):
|
||||
api_key = line.strip().split('=', 1)[1].strip('"\' ')
|
||||
|
||||
sample_transcript = """
|
||||
Doctor: नमस्कार, काय त्रास होतोय तुम्हाला?
|
||||
Patient: डॉक्टर मला गेले दोन दिवस झाले खूप खोकला आणि घशात खवखव होते आहे.
|
||||
Doctor: ताप येतोय का?
|
||||
Patient: हो, काल रात्री थोडा ताप आला होता.
|
||||
Doctor: ठीक आहे, मी तुम्हाला खोकल्याचे औषध आणि ताप कमी करण्यासाठी गोळ्या लिहून देतो, 3 दिवस घ्या.
|
||||
"""
|
||||
|
||||
prompt = """You are an expert clinical documentation AI. Read the doctor-patient conversation transcript below carefully.
|
||||
Extract the clinical summary strictly based on what was discussed in the transcript.
|
||||
Output ONLY valid JSON with no extra explanation or thought tags, formatted exactly as:
|
||||
{
|
||||
"chief_complaint": "Brief 1-line chief complaint based on transcript",
|
||||
"symptoms": ["List of all symptoms specifically mentioned in transcript"],
|
||||
"history": "Past history if mentioned, or 'Not mentioned'",
|
||||
"assessment": "Clinical assessment or condition discussed",
|
||||
"recommendation": "Doctor's exact advice, medication, or instructions from transcript"
|
||||
}"""
|
||||
|
||||
req = urllib.request.Request(
|
||||
'https://api.sarvam.ai/v1/chat/completions',
|
||||
data=json.dumps({
|
||||
'model': 'sarvam-105b-conversations',
|
||||
'temperature': 0.1,
|
||||
'max_tokens': 1000,
|
||||
'messages': [
|
||||
{'role': 'system', 'content': prompt},
|
||||
{'role': 'user', 'content': f"Transcript:\n{sample_transcript}"}
|
||||
]
|
||||
}).encode('utf-8'),
|
||||
headers={
|
||||
'Content-Type': 'application/json',
|
||||
'api-subscription-key': api_key
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
res = json.loads(resp.read().decode('utf-8'))
|
||||
print("Response:", res['choices'][0]['message']['content'])
|
||||
except Exception as e:
|
||||
print("Error:", e)
|
||||
Reference in New Issue
Block a user