Initial commit: Doctor-Patient clinical transcription and structured summary pipeline
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import os, json, urllib.request, urllib.error
|
||||
|
||||
_env_path = os.path.join(os.path.dirname(__file__), '.env')
|
||||
if os.path.exists(_env_path):
|
||||
with open(_env_path) as f:
|
||||
for line in f:
|
||||
if '=' in line and not line.startswith('#'):
|
||||
k, v = line.strip().split('=', 1)
|
||||
os.environ.setdefault(k, v)
|
||||
|
||||
SARVAM_API_KEY = os.getenv("SARVAM_API_KEY", "")
|
||||
|
||||
sample_text = """आपण हे dissection accelerated हे केले तुम्ही आधी इथं पहिल्यांदा सरांना दाखवले फक्त त्याच्या आधी हो इथं आधी पहिल्यापासून इथं treatment चालू आता एक फक्त आपल्या इथला एक नवीन हे चालू आहे EMR की जे directly audio connect करून इथं notes करतात त्याचं experimentation चालू आहे त्यासाठी फक्त जर तुमची परवानगी असेल तर आपलं जे conversation आहे ते record करतायत. चालेल तुम्हाला IT team-चं? म्हणजे आपण जे बोलतोय ना तेच फक्त record करणार जसं AI असतं ना AI घेऊन direct notes generate करतील असं त्यांचा प्रयोग चाललाय. अच्छा अच्छा. त्या intention-साठी आहे बाकी काही नाही. ठीक आहे. Okay that's okay. आधी तुमची treatment 4 cycle chemo झालेले आहेत. हो."""
|
||||
|
||||
prompt = """Format the conversation into Doctor and Patient turns:
|
||||
Doctor: ...
|
||||
Patient: ..."""
|
||||
|
||||
payload = json.dumps({
|
||||
"model": "sarvam-105b-conversations",
|
||||
"temperature": 0.1,
|
||||
"max_tokens": 1000,
|
||||
"messages": [
|
||||
{"role": "system", "content": prompt},
|
||||
{"role": "user", "content": sample_text}
|
||||
]
|
||||
}).encode('utf-8')
|
||||
|
||||
req = urllib.request.Request(
|
||||
'https://api.sarvam.ai/v1/chat/completions',
|
||||
data=payload,
|
||||
headers={'Content-Type': 'application/json', 'api-subscription-key': SARVAM_API_KEY}
|
||||
)
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
data = json.loads(resp.read().decode('utf-8'))
|
||||
import sys
|
||||
sys.stdout.buffer.write(data['choices'][0]['message']['content'].encode('utf-8'))
|
||||
sys.stdout.buffer.write(b"\n")
|
||||
except urllib.error.HTTPError as e:
|
||||
print("STATUS:", e.code)
|
||||
print("BODY:", e.read().decode('utf-8'))
|
||||
Reference in New Issue
Block a user