Spaces:
Runtime error
Runtime error
File size: 1,588 Bytes
e7aceea 2b4c43b e7aceea 6d89794 8b5626d 0c37dcb 6d89794 9bf3f26 6086021 e7aceea 9bf3f26 e7aceea b04895c 6086021 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import openai
import time
OPENAI_TRANSCRIPTION_MODEL='whisper-1'
OPENAI_COMPLETION_MODEL = "gpt-4o-mini"
TOKEN_LIMIT = 4096
openai_client = openai.OpenAI()
def openai_query(prompt):
response = openai_client.chat.completions.create(
model = OPENAI_COMPLETION_MODEL,
messages = [{'role': 'user',
'content': prompt}
],
temperature = 0, max_tokens = TOKEN_LIMIT,
top_p=1.0, frequency_penalty=0.0,
presence_penalty=0.0)
resp_text = response.choices[0].message.content
return resp_text
def nueva_ficha(resumen_historial, resumen_hoy):
new_prompt = f'''Escribe una nueva ficha médica, considerando el historial médico: "{resumen_historial}",
y también lo que ocurrió hoy: "{resumen_hoy}"
'''
nueva = openai_query(new_prompt)
return nueva
def whisper_transcribe(fn, temperature=0):
t0 = time.time()
audio_file = open(fn,'rb') # redundant?
whisper = openai_client.audio.transcriptions.create
transcript = whisper(model=OPENAI_TRANSCRIPTION_MODEL,
file=audio_file, language='es',
temperature=0.0) # to do, explore temperature
dt = round(time.time()-t0,2)
transcript = transcript.text
print(f'Whisper transcribe [dt={dt} secs]')
return transcript
def summarize(text):
prompt = f"Resume todos los aspectos médicos de esta consulta: '{text}'"
resp_text = openai_query(prompt)
return resp_text |