CoolFace
Apppublic

explorer13/risk-level-classification

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
App README

Risk Level Classification API

A real-time audio risk assessment API built for women's safety applications. When an SOS is triggered, the app captures audio and sends it here to determine the threat level.

How It Works

text
šŸŽ™ļø Audio (WAV, ≤35s)
    │
    ā–¼
šŸŽ§ Whisper (language detection from audio signal)
    │
    ā–¼
šŸ—£ļø Google STT (transcription in native script — Bengali, Devanagari, etc.)
    │
    ā–¼
šŸ”¤ Romanization (native script → Latin characters)
    │
    ā–¼
🌐 Translation (→ English)
    │
    ā–¼
šŸ¤– Risk Classification (Low / Medium / High + confidence score)

Key design decision: Whisper detects the language from audio acoustics (never confuses Hindi/Bengali), then Google STT transcribes using that language code (produces clean native script). Best of both worlds.

Quick Start

bash
curl -X POST "https://your-space.hf.space/analyze_audio" \
  -F "file=@recording.wav"

Example Response

json
{
  "original_text": "আমাকে আমার মত ঄াকতে দাও",
  "romanized_text": "amake amar moto thakte dao",
  "translated_text": "Let me be who I am",
  "risk_level": "Low",
  "score": 0.77
}

Running Locally

bash
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 7860

First run downloads Whisper medium (~1.42GB) and the risk classifier (~500MB).

Important: Do NOT use --reload — it restarts the process and re-downloads models.

API Endpoints

MethodPathDescription
GET/Status check
GET/healthHealth check (container orchestration)
GET/docsSwagger UI
POST/analyze_audioMain endpoint — analyze audio file

Tech Stack

ComponentTechnology
Language detectionOpenAI Whisper (medium, audio-based)
Speech-to-textGoogle Speech Recognition API
Translationdeep-translator (Google Translate)
RomanizationGoogle Translate romanization API
Risk classificationHuggingFace Transformers (sohampal0011/risk-classifier)
Web frameworkFastAPI + Uvicorn
RuntimePython 3.10, PyTorch CPU
DeploymentDocker on HuggingFace Spaces

Supported Languages

LanguageDetectionTranscriptionScript
Hindiāœ… Whisperāœ… Google STTDevanagari
Bengaliāœ… Whisperāœ… Google STTBengali
Englishāœ… Whisperāœ… Google STTLatin
18+ othersāœ… Whisperāœ… Google STTVarious

Audio Requirements

ConstraintValue
FormatWAV only
Max duration35 seconds
Sample rateAny (48kHz recommended)
ChannelsMono or stereo

Performance

MetricValue
Cold start~20-30s
Warm request (English)~3-5s
Warm request (Hindi/Bengali)~5-8s
Memory~1.5-2 GB

Documentation

See API_REQUIREMENTS.md for detailed technical documentation including:

  • —Full architecture diagrams
  • —Build pipeline details
  • —Deployment challenges & solutions
  • —Integration guide with code examples

License

MIT