Spaces:
Sleeping
Sleeping
File size: 3,193 Bytes
ed7adeb 88861c9 ed7adeb 88861c9 ed7adeb 88861c9 ed7adeb 88861c9 ed7adeb 3a8b599 ed7adeb 88861c9 ed7adeb 88861c9 |
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
from fastapi import FastAPI, File, UploadFile
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from groq import Groq
import os
from dotenv import load_dotenv
load_dotenv()
app = FastAPI()
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
@app.get("/")
def read_root():
return FileResponse("index.html")
@app.post("/transcribe/")
async def transcribe_audio(file: UploadFile = File(...)):
client = Groq(api_key=GROQ_API_KEY)
# Save the uploaded file temporarily
with open(file.filename, "wb") as buffer:
buffer.write(file.file.read())
# Transcribe the audio file
with open(file.filename, "rb") as audio_file:
transcription = client.audio.transcriptions.create(
file=(file.filename, audio_file.read()),
model="distil-whisper-large-v3-en",#"whisper-large-v3",
response_format="verbose_json",
)
# Remove the temporary file
os.remove(file.filename)
completion = client.chat.completions.create(
model="llama3-70b-8192",
messages=[
{
"role": "system",
"content": """convert the statement paramedic or doctor to the strictly as per below json schema\n\n
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Triage Assessment Form",
"type": "object",
"properties": {
"voiceObservation": {
"type": "string"
},
"patientInformation": {
"type": "object",
"properties": {
"patientName": { "type": "string" },
"age": { "type": "integer" },
"gender": { "type": "string", "enum": ["male", "female", "other"] }
},
"required": ["patientName", "age", "gender"]
},
"abcdeAssessment": {
"type": "object",
"properties": {
"airwayStatus": { "type": "string", "enum": ["clear", "obstructed", "partially obstructed"] },
"breathingStatus": { "type": "string", "enum": ["normal", "labored", "not breathing"] },
"circulationStatus": { "type": "string", "enum": ["normal", "weak", "absent"] },
"disabilityStatus": { "type": "string", "enum": ["alert", "verbal", "pain", "unresponsive"] },
"exposure": { "type": "string" }
},
"required": ["airwayStatus", "breathingStatus", "circulationStatus", "disabilityStatus", "exposure"]
},
"triageClassification": {
"type": "object",
"properties": {
"triageCategory": { "type": "string", "enum": ["red", "yellow", "green", "black"] },
"comments": { "type": "string" }
},
"required": ["triageCategory"]
}
},
"required": ["patientInformation", "abcdeAssessment", "triageClassification"]
}
"""
},
{
"role": "user",
"content": "conver the paramedic statement to json and no need to mention 'not specified in the statement' " + transcription.text
}
],
temperature=0.4,
top_p=1,
stream=False,
stop=None,
)
print(completion.choices[0].message.content or "", end="")
return {"transcription": transcription.text,"details":completion.choices[0].message.content} |