UdasriHasindu commited on
Commit ·
16af0dd
1
Parent(s): c58924d
add requirements.txt
Browse files- __init__.py +0 -0
- requirements.txt +52 -0
- routers/analyze_router.py +76 -0
__init__.py
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
annotated-doc==0.0.4
|
| 2 |
+
annotated-types==0.7.0
|
| 3 |
+
anyio==4.13.0
|
| 4 |
+
certifi==2026.2.25
|
| 5 |
+
click==8.3.1
|
| 6 |
+
dnspython==2.8.0
|
| 7 |
+
email-validator==2.3.0
|
| 8 |
+
fastapi==0.135.2
|
| 9 |
+
fastapi-cli==0.0.24
|
| 10 |
+
filelock==3.25.2
|
| 11 |
+
fsspec==2026.2.0
|
| 12 |
+
h11==0.16.0
|
| 13 |
+
hf-xet==1.4.2
|
| 14 |
+
httpcore==1.0.9
|
| 15 |
+
httptools==0.7.1
|
| 16 |
+
httpx==0.28.1
|
| 17 |
+
huggingface_hub==1.8.0
|
| 18 |
+
idna==3.11
|
| 19 |
+
joblib==1.5.3
|
| 20 |
+
lightgbm==4.6.0
|
| 21 |
+
markdown-it-py==4.0.0
|
| 22 |
+
mdurl==0.1.2
|
| 23 |
+
numpy==2.4.3
|
| 24 |
+
nvidia-nccl-cu12==2.29.7
|
| 25 |
+
packaging==26.0
|
| 26 |
+
pandas==3.0.1
|
| 27 |
+
praat-parselmouth==0.4.7
|
| 28 |
+
pydantic==2.12.5
|
| 29 |
+
pydantic_core==2.41.5
|
| 30 |
+
pydub==0.25.1
|
| 31 |
+
Pygments==2.19.2
|
| 32 |
+
python-dateutil==2.9.0.post0
|
| 33 |
+
python-dotenv==1.2.2
|
| 34 |
+
python-multipart==0.0.22
|
| 35 |
+
PyYAML==6.0.3
|
| 36 |
+
rich==14.3.3
|
| 37 |
+
rich-toolkit==0.19.7
|
| 38 |
+
scikit-learn==1.8.0
|
| 39 |
+
scipy==1.17.1
|
| 40 |
+
shellingham==1.5.4
|
| 41 |
+
six==1.17.0
|
| 42 |
+
starlette==1.0.0
|
| 43 |
+
threadpoolctl==3.6.0
|
| 44 |
+
tqdm==4.67.3
|
| 45 |
+
typer==0.24.1
|
| 46 |
+
typing-inspection==0.4.2
|
| 47 |
+
typing_extensions==4.15.0
|
| 48 |
+
uvicorn==0.42.0
|
| 49 |
+
uvloop==0.22.1
|
| 50 |
+
watchfiles==1.1.1
|
| 51 |
+
websockets==16.0
|
| 52 |
+
xgboost==3.2.0
|
routers/analyze_router.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Form, File, UploadFile, HTTPException
|
| 2 |
+
from services.voice_analyze_service import process_audio_and_predict
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
router = APIRouter(
|
| 6 |
+
prefix="/analyze",
|
| 7 |
+
tags=["analyze"],
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
@router.post("/test")
|
| 11 |
+
async def test_endpoint(
|
| 12 |
+
name: str = Form(...),
|
| 13 |
+
age: int = Form(...),
|
| 14 |
+
sex: str = Form(...),
|
| 15 |
+
test_time: float = Form(...),
|
| 16 |
+
audio_file: UploadFile = File(...)):
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
return {
|
| 20 |
+
"received_data": {
|
| 21 |
+
"name": name,
|
| 22 |
+
"age": age,
|
| 23 |
+
"sex": sex,
|
| 24 |
+
"test_time": test_time,
|
| 25 |
+
"audio_file": {
|
| 26 |
+
"filename": audio_file.filename,
|
| 27 |
+
"content_type": audio_file.content_type,
|
| 28 |
+
"size": len(await audio_file.read()) if audio_file else 0
|
| 29 |
+
}
|
| 30 |
+
},
|
| 31 |
+
"status": "success"
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
@router.post("/voice")
|
| 35 |
+
async def analyze_voice(
|
| 36 |
+
name: str = Form(..., min_length=1, max_length=100),
|
| 37 |
+
age: int = Form(..., gt=10, lt=120),
|
| 38 |
+
sex: str = Form(..., pattern="^(male|female)$"),
|
| 39 |
+
test_time: float = Form(..., gt=0),
|
| 40 |
+
audio_file: UploadFile = File(...) ):
|
| 41 |
+
|
| 42 |
+
# for debugging
|
| 43 |
+
print("-" * 20)
|
| 44 |
+
print("RECEIVED REQUEST FROM FRONTEND:")
|
| 45 |
+
print(f" Name: {name}")
|
| 46 |
+
print(f"Age: {age}")
|
| 47 |
+
print(f"Sex: {sex}")
|
| 48 |
+
print(f"Test Time: {test_time}")
|
| 49 |
+
print(f"Audio File: {audio_file.filename} ")
|
| 50 |
+
print(f"Audio Content Type: {audio_file.content_type}")
|
| 51 |
+
|
| 52 |
+
# validation checks
|
| 53 |
+
if not audio_file or audio_file.filename == "":
|
| 54 |
+
print("---No audio file provided! ---")
|
| 55 |
+
raise HTTPException(status_code=400, detail="No audio file provided")
|
| 56 |
+
|
| 57 |
+
if audio_file.content_type and not audio_file.content_type.startswith(('audio/', 'application/octet-stream')):
|
| 58 |
+
print(f"Unusual content type: {audio_file.content_type}")
|
| 59 |
+
|
| 60 |
+
print("-" * 20)
|
| 61 |
+
|
| 62 |
+
basic_info = {"age": age, "sex": sex, "name": name, "test_time": test_time}
|
| 63 |
+
print(f"Basic info being passed to service: {basic_info}")
|
| 64 |
+
|
| 65 |
+
try:
|
| 66 |
+
result = await process_audio_and_predict(audio_file, basic_info)
|
| 67 |
+
|
| 68 |
+
print("\nSENDING RESPONSE TO FRONTEND:")
|
| 69 |
+
print(f"Response: {result}\n")
|
| 70 |
+
return result
|
| 71 |
+
except Exception as e:
|
| 72 |
+
print("=" * 50)
|
| 73 |
+
print("ERROR OCCURRED:")
|
| 74 |
+
print(f"Error: {str(e)}")
|
| 75 |
+
print(f"Error type: {type(e).__name__}\n")
|
| 76 |
+
raise e
|