Spaces:
Runtime error
Runtime error
Download config.py from sae8d/ishraq-quran-backend: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/spaces/sae8d/ishraq-quran-backend/resolve/main/config.py
- Command line
-
hf download hf://spaces/sae8d/ishraq-quran-backend/config.py
-
curl -L -o config.py https://huggingface.co/spaces/sae8d/ishraq-quran-backend/resolve/main/config.py
2.58 kB
| """ | |
| Configuration management for Quran Transcription API | |
| """ | |
| import os | |
| from typing import Optional | |
| from pathlib import Path | |
| # Handle both pydantic v1 and v2 | |
| try: | |
| from pydantic_settings import BaseSettings | |
| except ImportError: | |
| from pydantic import BaseSettings | |
| class Settings(BaseSettings): | |
| """Application settings loaded from environment variables and .env file""" | |
| # Server configuration | |
| host: str = "0.0.0.0" | |
| port: int = 8888 | |
| reload: bool = False | |
| workers: int = 1 | |
| # API configuration | |
| title: str = "Quran Recitation Transcription API" | |
| description: str = "Arabic/Quran speech-to-text service using Faster-Whisper" | |
| version: str = "1.0.0" | |
| # CORS configuration | |
| cors_origins: str = "http://localhost:3000,http://localhost:5173" | |
| # Model configuration | |
| whisper_model: str = "OdyAsh/faster-whisper-base-ar-quran" | |
| compute_type: str = "float32" # float32, float16, int8 | |
| device: Optional[str] = None # auto-detect if None | |
| # GPU configuration | |
| cuda_visible_devices: Optional[str] = "0" | |
| # File configuration | |
| max_file_size_mb: int = 100 | |
| allowed_audio_formats: list[str] = ["mp3", "wav", "flac", "m4a", "aac", "ogg", "opus", "webm"] | |
| # Logging configuration | |
| log_level: str = "INFO" | |
| # Transcription parameters | |
| beam_size: int = 1 | |
| vad_filter: bool = True | |
| vad_min_silence_duration_ms: int = 500 | |
| language: str = "ar" | |
| class Config: | |
| env_file = ".env" | |
| env_file_encoding = "utf-8" | |
| case_sensitive = False | |
| # Example values for documentation | |
| json_schema_extra = { | |
| "example": { | |
| "host": "0.0.0.0", | |
| "port": 8888, | |
| "whisper_model": "OdyAsh/faster-whisper-base-ar-quran", | |
| "compute_type": "float32" | |
| } | |
| } | |
| def get_settings() -> Settings: | |
| """Get settings instance with cached results""" | |
| return Settings() | |
| def get_device() -> str: | |
| """Determine device based on CUDA availability and environment""" | |
| import torch | |
| settings = get_settings() | |
| if settings.device: | |
| return settings.device | |
| # Auto-detect | |
| if settings.cuda_visible_devices and torch.cuda.is_available(): | |
| return "cuda" | |
| return "cpu" | |
| def get_cors_origins() -> list[str]: | |
| """Parse CORS origins from settings""" | |
| settings = get_settings() | |
| return [origin.strip() for origin in settings.cors_origins.split(",")] | |
| # Export settings instance | |
| settings = get_settings() | |