Skip to main content

Multimodal AI server for Indian languages (speech, vision, LLMs, TTS, ASR, etc.)

Project description

Dhwani Server

Dhwani API is a FastAPI-based application providing AI-powered services for Indian languages, including text-to-speech (TTS), language model (LLM) chat, vision-language model (VLM) capabilities, and automatic speech recognition (ASR). It supports lazy loading of models for fast startup and includes endpoints for various tasks.

Features

  • Text-to-Speech (TTS): Generate audio from text in Indian languages using Parler TTS.
  • Chat: Process Kannada prompts and respond in Kannada via translation and LLM.
  • Vision-Language Model (VLM): Caption images, answer visual queries, detect, and point objects.
  • Automatic Speech Recognition (ASR): Transcribe audio files in multiple Indian languages.
  • Lazy Loading: Models load on-demand or via an explicit endpoint for fast startup.

Prerequisites

  • **System Requirements - User **:

    • Python: 3.10
    • Ubuntu 22.04
    • git
    • vscode
  • **System Requirements - Server **:

    • Ubuntu with sufficient RAM (16GB+ recommended for models).
    • Optional: NVIDIA GPU with CUDA support for faster inference.
  • FFmpeg: Required for audio processing (ASR).

  • Server Setup

export HF_HOME=/home/ubuntu/data-dhwani-models
export HF_TOKEN='YOur-HF-token'
python src/server/main.py --host 0.0.0.0 --port 7860 --config config_two

Installation

  1. Clone the Repository:

    git clone https://github.com/slabstech/dhwani-server
    cd dhwani-server
    
  2. Install Libraries:

    • On Ubuntu: sudo apt-get install ffmpeg build-essential
  3. Set Up Virtual Environment:

    python -m venv venv
    source venv/bin/activate 
    
  4. Install Dependencies:

    sudo apt-get install -y ffmpeg build-essential
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal
    . "$HOME/.cargo/env"
    export CC=/usr/bin/gcc
    export ENV CXX=/usr/bin/g++
    
    pip install --no-cache-dir --upgrade pip setuptools psutil setuptools-rust torch==2.6.0
    pip install --no-cache-dir flash-attn --no-build-isolation
    
    pip install -r requirements.txt
    
  5. Set Environment Variable: Create a .env file in the root directory and add your API key: plaintext

    API_KEY=your_secret_key
    
  6. Running the Server

    • Start the Server:
        python src/server/main.py --host 0.0.0.0 --port 7860 --config config_two
    
    • The server starts with models loaded on start

    • Access the interactive API docs at http://localhost:7860/docs.

    • (Optional) Load All Models: Preload all models (LLM, Translation, TTS, VLM, ASR) with:

    curl -X POST "http://localhost:7860/load_all_models" -H "X-API-Key: your_secret_key"
    
  • Usage

    • Endpoints

      • All endpoints require the X-API-Key header with the value from your .env file.
    • Health Check: GET /health

        curl "http://localhost:7860/health"
    
    • Response:

      {"status": "healthy", "model": "Qwen/Qwen2.5-3B-Instruct"}
      
    • Text-to-Speech: POST /v1/audio/speech

    curl -X POST "http://localhost:7860/v1/audio/speech" -H "X-API-Key: your_secret_key" -H "Content-Type: application/json" -d '{"input": "ನಮಸ್ಕಾರ", "voice": "Female voice", "model": "ai4bharat/indic-parler-tts", "response_format": "mp3"}' --output speech.mp3
    
    • Chat: POST /chat
        curl -X POST "http://localhost:7860/chat" -H "X-API-Key: your_secret_key" -H "Content-Type: application/json" -d '{"prompt": "ನೀವು ಹೇಗಿದ್ದೀರಿ?"}'
    
    • Response: {"response": "<Kannada response>"}
    • Image Captioning: POST /caption/
        curl -X POST "http://localhost:7860/caption/" -H "X-API-Key: your_secret_key" -F "file=@image.jpg" -F "length=short"
    
    • Response: {"caption": "<short caption>"}
    • Visual Query: POST /visual_query/
        curl -X POST "http://localhost:7860/visual_query/" -H "X-API-Key: your_secret_key" -F "file=@image.jpg" -F "query=What is this?"
    
    • Response: {"answer": "<answer>"}
    • Object Detection: POST /detect/
        curl -X POST "http://localhost:7860/detect/" -H "X-API-Key: your_secret_key" -F "file=@image.jpg" -F "object_type=face"
    
    • Response: {"objects": [<list of detected objects>]}
    • Object Pointing: POST /point/
        curl -X POST "http://localhost:7860/point/" -H "X-API-Key: your_secret_key" -F "file=@image.jpg" -F "object_type=person"
    
    • Response: {"points": [<list of points>]}
    • Transcription: POST /transcribe/
    curl -X POST "http://localhost:7860/transcribe/?language=kannada" -H "X-API-Key: your_secret_key" -F "file=@audio.wav"
    
    • Response: {"text": "<transcribed text>"}
    • Batch Transcription: POST /transcribe_batch/
    curl -X POST "http://localhost:7860/transcribe_batch/?language=kannada" -H "X-API-Key: your_secret_key" -F "files=@audio1.wav" -F "files=@audio2.mp3"
    
    • Response: {"transcriptions": ["<text1>", "<text2>"]}
  • Notes

    • Lazy Loading: Models load on first use or via /load_all_models. Expect a delay on the first request for each model type. Supported Languages: ASR supports multiple Indian languages (e.g., kannada, hindi, tamil); see models/asr.py for the full list. Logs: Check dhwani_api.log for detailed logs (rotated at 10MB, 5 backups). Performance: Use a GPU with flash-attn installed for faster TTS and ASR inference.
  • Troubleshooting

    • Module Errors: Ensure all dependencies are installed. Re-run pip install if needed. FFmpeg Not Found: Install FFmpeg and ensure it’s in your PATH. Permission Denied: Run with sudo if accessing restricted ports (e.g., < 1024).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dwani-0.1.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dwani-0.1.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file dwani-0.1.2.tar.gz.

File metadata

  • Download URL: dwani-0.1.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for dwani-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0851c24c825378e2a117c58cbd8310920ab92aac953e96c9909eb4be5451afb3
MD5 b5d2d102a60ff86b9310d0ad56cc58d3
BLAKE2b-256 080632de4d8efd2b1b690449ff2f73ec1dbe0d2401ae91d90c4134bf82be31b9

See more details on using hashes here.

File details

Details for the file dwani-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: dwani-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for dwani-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 343ba63f82ed826f6e3f560fa0ff48f8069c1fced14515d07ed00d7caefd31ca
MD5 40d2a9a0abd1e25ee039de24053b0493
BLAKE2b-256 6b65aca7aa9981c8e3468d7d3bc487621eb9f4da6066362e66c4c47673f7fda2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page