diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..3dbe7acc2f3c04d20ef6a30919aa16dafbc00bb7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +.git +.github +.venv +venv +env +__pycache__ +*.pyc +.pytest_cache +.ruff_cache +audio_outputs/*.mp3 +frontend/node_modules +frontend/dist +.cache +tests diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000000000000000000000000000000000..06631aa4a8f1ba20e1488d9c8b06528270c8848e --- /dev/null +++ b/.env.example @@ -0,0 +1,25 @@ +# Copy to .env and adjust as needed. All values have sensible defaults in +# app/core/config.py; nothing here is required to run. + +# --- Server --- +EMPATHVOICE_HOST=127.0.0.1 +EMPATHVOICE_PORT=8000 + +# --- Models --- +EMPATHVOICE_EMOTION_MODEL=SamLowe/roberta-base-go_emotions +EMPATHVOICE_VAD_MODEL=RobroKools/vad-bert +# Force a device, or leave unset for auto-detect (cuda if available, else cpu). +# EMPATHVOICE_DEVICE=cpu +# Max concurrent model inferences (shared model instance). 1 = serialize. +EMPATHVOICE_INFERENCE_CONCURRENCY=1 + +# --- Audio --- +EMPATHVOICE_AUDIO_DIR=audio_outputs +EMPATHVOICE_AUDIO_TTL_SECONDS=3600 +EMPATHVOICE_DEFAULT_VOICE=en-IN-NeerjaNeural + +# --- Limits --- +EMPATHVOICE_MAX_TEXT_CHARS=2000 + +# --- Logging --- +EMPATHVOICE_LOG_LEVEL=INFO diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..d86b51eb20e5278df58483da5b86d2df348e83d2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# Normalize line endings so the working tree stops showing phantom CRLF diffs. +# Text files are stored with LF in the repo and checked out with LF everywhere. +* text=auto eol=lf + +# Binary assets: never touch. +*.mp3 binary +*.png binary +*.pt binary +*.bin binary diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..9dd2132cbeb9872caae37b3c7c3b41d9e23c2d58 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + backend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install dependencies + run: pip install -r requirements-dev.txt + # The default suite mocks models + TTS (integration tests are + # deselected), so CI never downloads pretrained weights or calls edge-tts. + - name: Lint + run: ruff check app tests + - name: Test + run: pytest + + frontend: + runs-on: ubuntu-latest + defaults: + run: + working-directory: frontend + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "20" + - run: npm ci + - name: Type-check and build + run: npm run build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5d3e801a6f40aa4a05ec0693ea63b2b83ffff241 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Python +__pycache__/ +*.py[cod] +*.egg-info/ +.venv/ +venv/ +env/ + +# Local environment / secrets +.env +.env.* +!.env.example + +# Generated audio (runtime artifacts, never committed) +audio_outputs/ +!audio_outputs/.gitkeep + +# Hugging Face / Torch caches +.cache/ +*.pt +*.bin + +# Tooling +.pytest_cache/ +.ruff_cache/ +.mypy_cache/ +htmlcov/ +.coverage + +# Frontend (added in Stage 4) +node_modules/ +frontend/dist/ +*.tsbuildinfo + +# OS / editor +.DS_Store +Thumbs.db +.idea/ +.vscode/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..ebfc6c3cada8be93d386138aea5fe94a8fbfdbe8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +# Stage 1: Build the React + TypeScript frontend +FROM node:20-slim AS frontend-builder +WORKDIR /frontend + +COPY frontend/package*.json ./ +RUN npm ci + +COPY frontend/ ./ +RUN npm run build + +# Stage 2: Python backend + serving +FROM python:3.12-slim + +# Hugging Face Spaces runs as user ID 1000 +RUN useradd -m -u 1000 user +USER user +ENV HOME=/home/user \ + PATH=/home/user/.local/bin:$PATH \ + PYTHONUNBUFFERED=1 \ + HF_HOME=/home/user/.cache/huggingface \ + EMPATHVOICE_HOST=0.0.0.0 \ + EMPATHVOICE_PORT=7860 + +WORKDIR $HOME/app + +# Install Python runtime dependencies +COPY --chown=user:user requirements.txt . +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt + +# Pre-cache models into the container image for fast cold-starts +RUN python -c "from transformers import AutoModelForSequenceClassification, AutoTokenizer; \ +AutoTokenizer.from_pretrained('SamLowe/roberta-base-go_emotions'); \ +AutoModelForSequenceClassification.from_pretrained('SamLowe/roberta-base-go_emotions'); \ +AutoTokenizer.from_pretrained('RobroKools/vad-bert'); \ +AutoModelForSequenceClassification.from_pretrained('RobroKools/vad-bert')" + +# Copy backend code +COPY --chown=user:user app ./app +COPY --chown=user:user run.py . + +# Copy built frontend assets from builder stage +COPY --chown=user:user --from=frontend-builder /frontend/dist ./frontend/dist + +# Create audio outputs directory +RUN mkdir -p audio_outputs + +# Hugging Face Spaces exposes port 7860 by default +EXPOSE 7860 + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"] diff --git a/README.md b/README.md index 0444662965122bd97d759f67c44fab6d636617fd..5b7caf61f4042c29b69026657c336f642fe36250 100644 --- a/README.md +++ b/README.md @@ -1,181 +1,286 @@ # EmpathVoice -EmpathVoice is a FastAPI-based text-to-speech service that tries to make generated voice sound emotionally appropriate. +Emotion-aware text-to-speech with a transparent prosody pipeline. + +[![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-yellow)](https://huggingface.co/spaces) +[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) +[![React 18](https://img.shields.io/badge/react-18-61dafb.svg)](https://react.dev/) +[![FastAPI](https://img.shields.io/badge/FastAPI-0.162+-009688.svg)](https://fastapi.tiangolo.com/) + +EmpathVoice reads a piece of text, estimates its emotional character with two +complementary models, maps that estimate to concrete speech-delivery parameters +(pitch, rate, energy, pauses), and synthesizes audio whose delivery reflects the +text. The thing I care about most here is **transparency**: instead of a +black-box "expressive TTS", the app shows you *why* it chose a particular +delivery, directly from the model outputs. + +> The emotion and VAD numbers are **model estimates**, not calibrated +> probabilities or a definitive reading of anyone's feelings. The UI and the API +> describe them that way on purpose. + +--- + +## Preview + +

+ EmpathVoice UI Screenshot +

+ +--- + +## Motivation + +Most expressive-TTS demos hide their reasoning: text goes in, "emotional" audio +comes out, and you can't tell what the system thought the text meant. I wanted +the opposite — a small, honest studio where the emotion analysis is explicit, +interpretable, and visibly drives the voice. The analysis pipeline is +deterministic and inspectable, which makes it easy to reason about, debug, and +explain. + +## Features + +- **Live emotion analysis preview** — as you type, the app shows the estimated + emotions, the valence/arousal/dominance (VAD) estimate, and the resulting + pitch/rate/energy/pause adjustments, all computed by the backend. +- **One-click synthesis** — generate speech that applies those parameters, then + play, replay, and download the result. +- **Voice selection** — a set of English edge-tts voices. +- **Transparent delivery** — every number shown comes from the real pipeline; + there is no client-side keyword guessing. +- **Clean failure and warm-up handling** — the UI reports when models are still + loading or unavailable, and the API returns structured errors. + +## Architecture + +```mermaid +flowchart LR + UI[React + TS UI] -- POST /api/analyze --> API[FastAPI] + UI -- POST /api/synthesize --> API + UI -- GET /api/audio/:id --> API + API --> MGR[Model Manager
lifespan, device, eval, concurrency] + MGR --> EMO[GoEmotions] + MGR --> VAD[VAD-BERT] + API --> PIPE[Emotion→Prosody pipeline
mappings · fusion · clamp] + API --> TTS[edge-tts] + API --> STORE[Audio store
TTL · id-based] +``` -In simple words: +The backend is organized by responsibility: HTTP/API layer, request/response +schemas, configuration, model lifecycle, the emotion→prosody pipeline, TTS, and +audio storage are each isolated. A fuller write-up — request lifecycle, the +model-readiness model, the fusion math, and the main design decisions — is in +[`docs/architecture.md`](docs/architecture.md). -- You give text. -- The system detects emotion. -- It changes vocal controls (pitch, rate, energy, pauses). -- It returns an MP3 with emotion-aware delivery. +## The AI pipeline -## Core Contribution (Quick Overview) +The core is a deterministic, interpretable **hybrid emotion-to-prosody +controller**. Two views of the text's emotion are combined: -The main idea is a deterministic hybrid emotion-to-prosody controller. +1. **Discrete branch** — `SamLowe/roberta-base-go_emotions` produces a + 28-dimensional multi-label score vector. A handcrafted 28×4 weight matrix maps + those labels to a prosody shift `[pitch, rate, energy, pauses]`. The matrix is + aligned to the model's labels *by name*, so it stays correct regardless of + label ordering. +2. **Continuous branch** — `RobroKools/vad-bert` estimates valence, arousal, and + dominance in `[0, 1]`. These are centered to `[-1, 1]`, passed through a + `tanh` nonlinearity, and mapped to the same prosody space by a 4×3 matrix. -Instead of a black-box end-to-end prosody model, we explicitly combine two emotional views: +The two shifts are combined with a **confidence-adaptive fusion**: the top +*non-neutral* discrete score sets how much the categorical branch is trusted +versus the smoother VAD branch, per prosody dimension. (Excluding `neutral` from +the confidence term is a deliberate fix — otherwise neutral text, whose discrete +prosody row is all zeros, would suppress the VAD branch and flatten delivery.) -1. Discrete emotion space (28-label GoEmotions probabilities) -2. Continuous affective space (Valence-Arousal-Dominance) +The fused vector is scaled and **clamped** to safe TTS ranges, then applied via +edge-tts (pitch in Hz, rate and volume in percent). Because edge-tts does not +expose SSML `` control, pauses are approximated by inserting commas at +clause boundaries, scaled by the pause level. -These two state spaces are mapped to the same 4 vocal parameters and fused using confidence-adaptive weights. +**Honesty note:** the weight matrices and clamps are hand-tuned heuristics, not +learned or formally evaluated. I make no claims about emotion-recognition +accuracy or "emotional quality"; the value here is interpretability and a clean, +controllable mapping, not state-of-the-art affect modeling. -This keeps the system interpretable, controllable, and easy to debug. +## Tech stack -## Demo (Frontend Preview) +- **Backend:** Python 3.10+, FastAPI, Pydantic v2, PyTorch, Hugging Face + Transformers, NumPy, edge-tts. +- **Frontend:** React 18, TypeScript, Vite. +- **Testing:** pytest (unit + API with fakes; optional integration tests). - -![Demo Placeholder](frontend.png) +## Project structure -## High-Level Methodology +```text +EmpathVoice/ +├── app/ +│ ├── main.py # app factory, lifespan, routing, SPA serving +│ ├── core/ # config, logging, error handling +│ ├── schemas.py # Pydantic request/response contracts +│ ├── ml/ # model wrappers + lifecycle manager +│ ├── emotion/ # weights, VAD mapping, fusion, prosody, pipeline +│ ├── tts/ # pause injection, synthesizer, voices +│ ├── audio/ # TTL audio store +│ └── api/ # one module per route group +├── frontend/ # React + TypeScript + Vite app +├── tests/ # unit, API, and optional integration tests +├── docs/architecture.md +├── requirements.txt / requirements-dev.txt +└── run.py +``` -### 1) Emotion inference from two state spaces +## Setup -- Discrete branch: GoEmotions gives a 28-dimensional multi-label probability vector. -- Continuous branch: VAD model gives valence, arousal, dominance in [0, 1]. +### Backend -### 2) Deterministic mappings to vocal parameter space +```bash +cd EmpathVoice +python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate +pip install -r requirements.txt +``` -Both branches are mapped to the same prosody state: +PyTorch and Transformers download the pretrained models on first use (a few +hundred MB). CUDA is used automatically when available; otherwise it runs on CPU. -$$ -\mathbf{s} = [\text{pitch},\,\text{rate},\,\text{energy},\,\text{pauses}] -$$ +### Frontend -- Discrete mapping: handcrafted matrix from 28 emotions to 4 prosody controls. -- Continuous mapping: VAD transform (with nonlinearity) to the same 4 controls. +```bash +cd frontend +npm install +``` -This deterministic mapping layer is the central design choice of this project. +## Environment configuration -### 3) Confidence-adaptive fusion (key integration logic) +All settings have defaults, so no configuration is required. To override, copy +`.env.example` to `.env`. Variables use the `EMPATHVOICE_` prefix — model names, +`DEVICE` (auto-detected if unset), `INFERENCE_CONCURRENCY`, `AUDIO_TTL_SECONDS` +(default 3600), `DEFAULT_VOICE`, `MAX_TEXT_CHARS`, and `LOG_LEVEL`. -Let: +## Running -- $\mathbf{s}_{disc}$ = prosody from discrete branch -- $\mathbf{s}_{cont}$ = prosody from VAD branch -- $c = (\max_i p_i)^\kappa$ = confidence from top discrete probability +### Development (two processes, hot reload) -Fusion is: +```bash +# Terminal 1 — backend on :8000 +python run.py -$$ -\mathbf{s}_{final} = \mathbf{w}_d \odot (\mathbf{G}_d \odot \mathbf{s}_{disc}) + \mathbf{w}_c \odot (\mathbf{G}_c \odot \mathbf{s}_{cont}) -$$ +# Terminal 2 — frontend on :5173 (proxies /api and probes to :8000) +cd frontend && npm run dev +``` -with +Open http://127.0.0.1:5173. -$$ -\mathbf{w}_d = c\,\boldsymbol{\alpha}, \quad \mathbf{w}_c = 1-\mathbf{w}_d -$$ +### Production-style (single process) -Why this matters: +Build the frontend; FastAPI then serves it from `frontend/dist` at `/`: -- High discrete confidence -> stronger categorical influence. -- Lower confidence -> smoother fallback from VAD branch. -- Per-dimension priors allow different trust levels for pitch/rate/energy/pauses. +```bash +cd frontend && npm run build && cd .. +uvicorn app.main:app --host 0.0.0.0 --port 8000 # no --reload: models load once +``` -## Post-Processing for TTS Control +Open http://127.0.0.1:8000. If the frontend isn't built, `/` redirects to the +interactive API docs at `/docs`. -The fused prosody vector is converted into bounded TTS controls for edge-tts: +### Docker (Local) -- pitch shift (Hz) -- speaking rate (%) -- energy/volume (%) -- pause control scalar +Run the entire application in a self-contained container: -Although SSML-level fine control is not integrated, the project still applies prosody modulation and includes an intra-sentence pause strategy module. +```bash +docker build -t empathvoice . +docker run -p 7860:7860 empathvoice +``` -## Project Structure +Open http://127.0.0.1:7860. -```text -DarvixProject/ -├── README.md -├── readme1.md -├── requirements.txt -├── run.py -├── app/ -│ ├── config.py -│ ├── main.py -│ ├── models/ -│ │ ├── emotion_model.py -│ │ └── vad_model.py -│ ├── services/ -│ │ └── engine.py -│ ├── static/ -│ │ ├── index.html -│ │ ├── style.css -│ │ └── script.js -│ ├── tts/ -│ │ ├── pause_injection.py -│ │ └── tts_engine.py -│ └── utils/ -│ ├── emotion_weights.py -│ ├── fusion.py -│ ├── processing.py -│ └── vad_mapping.py -└── audio_outputs/ -``` +--- -## Setup +## Deployment & Live Demo -```bash -cd DarvixProject -pip install -r requirements.txt -``` +Because EmpathVoice runs two PyTorch transformer models in memory (`RoBERTa-GoEmotions` and `VAD-BERT`), it requires at least ~1.5 GB of RAM. -Recommended: +### Deploying to Hugging Face Spaces (Recommended — Free 16GB RAM) -- Python 3.9+ -- CUDA-enabled PyTorch (optional, for faster inference) +[Hugging Face Spaces](https://huggingface.co/spaces) is the ideal host for this project: -## Run +1. **Create a Space**: Go to [huggingface.co/new-space](https://huggingface.co/new-space). +2. **Select Space SDK**: Choose **Docker** (Blank template). +3. **Hardware Tier**: Select the **Free** tier (2 vCPU, 16 GB RAM). +4. **Deploy**: + - Push this repository directly to the Hugging Face Space Git remote: + ```bash + git remote add space https://huggingface.co/spaces// + git push space main + ``` + - *Or* connect your GitHub repository directly in the Space settings for automatic deployment on push. +5. Hugging Face builds the included `Dockerfile` (which pre-caches the models) and hosts your live app at `https://huggingface.co/spaces//`. -```bash -cd DarvixProject -python run.py -``` +### Deploying to Railway or Render -Service URL: +* **Railway**: Connect your GitHub repository. Railway automatically detects the `Dockerfile` and deploys it with containerized memory allocation. +* **Render**: Deploy as a Web Service from Git or Docker. Select at least the **Starter tier (2 GB RAM)**, as the Free tier (512 MB RAM) will hit Out-Of-Memory limits when loading PyTorch models. -- http://127.0.0.1:8000 +--- ## API -### POST /speak +Interactive docs live at `/docs`. Summary: -Input: +| Method | Path | Purpose | +| ------ | -------------------- | --------------------------------------------------- | +| GET | `/health` | Liveness — process is up (always 200). | +| GET | `/ready` | Readiness — 200 when models are loaded, else 503. | +| POST | `/api/analyze` | Emotion → prosody analysis (no audio). | +| POST | `/api/synthesize` | Analysis + synthesized audio. | +| GET | `/api/audio/{id}` | Retrieve generated audio by id (expires via TTL). | +| GET | `/api/voices` | Available voices + default. | -- query parameter: text - -Example: +Examples: ```bash -curl -X POST "http://127.0.0.1:8000/speak?text=I%20am%20proud%20of%20you" +curl -s -X POST http://127.0.0.1:8000/api/analyze \ + -H 'Content-Type: application/json' \ + -d '{"text": "I am so proud of you!"}' + +curl -s -X POST http://127.0.0.1:8000/api/synthesize \ + -H 'Content-Type: application/json' \ + -d '{"text": "I am so proud of you!", "voice": "en-US-AriaNeural"}' +# -> { "audio_id": "...", "audio_url": "/api/audio/...", "expires_in_seconds": 3600, "analysis": {...} } ``` -Response: - -```json -{ - "audio": "audio_out/.mp3" -} -``` - -## Design Rationale - -1. Hybrid emotion modeling - - Categorical labels capture semantic emotion type. - - VAD captures smooth affective intensity. +Errors are returned as `{"error": {"code", "message"}}` with an appropriate +status code (e.g. `model_not_ready` → 503, `invalid_request` → 400, +`audio_not_found` → 404). Input validation errors use FastAPI's 422. -2. Deterministic mapping instead of black-box prosody generation - - Better interpretability and direct control over behavior. +## Testing -3. Confidence-adaptive fusion - - Robust under ambiguity; branch contribution is input-dependent. - -4. Practical deployability - - FastAPI + edge-tts pipeline is simple and easy to demo. - -## Note +```bash +pip install -r requirements-dev.txt -Recent/sample generated audio files can be found in the `audio_outputs/` folder. +pytest # unit + API tests (fakes; no downloads, no network) +pytest -m integration # optional: loads real models + calls edge-tts +``` +The default suite mocks the models and the TTS service, so it is fast and +hermetic. The integration tests exercise the real inference and synthesis paths +and skip cleanly when torch / edge-tts are unavailable. + +## Known limitations + +- Prosody mappings and clamps are hand-tuned heuristics; there is no learned + prosody model and no formal evaluation of emotional fidelity. +- A single prosody setting is applied to the whole input — long, mixed-emotion + passages are not segmented per sentence. +- Pause control is approximate (comma insertion), because edge-tts does not + expose SSML break timing. +- Synthesis depends on the external edge-tts (Microsoft) service and needs + network access; voice quality is whatever that service provides. +- Generated audio is intentionally temporary (1-hour TTL) and not persisted + across restarts. + +## Possible future improvements + +- Per-sentence prosody for mixed-emotion passages (multi-segment synthesis). +- An expressiveness control (the backend already accepts a global strength + parameter; it is intentionally not exposed in the current UI). +- A pluggable TTS backend that supports true SSML prosody/break control. +- Calibration of the emotion scores if a labelled dataset is introduced. diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/__pycache__/config.cpython-312.pyc b/app/__pycache__/config.cpython-312.pyc deleted file mode 100644 index c4e65628ebe66387d751f4be5b003f9b7d76d2c5..0000000000000000000000000000000000000000 Binary files a/app/__pycache__/config.cpython-312.pyc and /dev/null differ diff --git a/app/__pycache__/main.cpython-312.pyc b/app/__pycache__/main.cpython-312.pyc deleted file mode 100644 index 57675610af5213b85bed4df6a972966904982fb0..0000000000000000000000000000000000000000 Binary files a/app/__pycache__/main.cpython-312.pyc and /dev/null differ diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/api/analyze.py b/app/api/analyze.py new file mode 100644 index 0000000000000000000000000000000000000000..a91a132195be933df346aeec2242acc3ec8e2b2e --- /dev/null +++ b/app/api/analyze.py @@ -0,0 +1,28 @@ +"""Emotion-analysis endpoint. + +Returns the full emotion -> prosody analysis without synthesizing audio, so the +frontend can preview *why* the voice will sound a certain way before committing +to a (slower) synthesis call. +""" + +from __future__ import annotations + +from fastapi import APIRouter, Depends + +from app.api.deps import get_manager +from app.core.errors import ModelNotReadyError +from app.ml.manager import ModelManager +from app.schemas import AnalyzeRequest, AnalyzeResponse + +router = APIRouter(tags=["analysis"]) + + +@router.post("/analyze", response_model=AnalyzeResponse) +async def analyze( + payload: AnalyzeRequest, manager: ModelManager = Depends(get_manager) +) -> AnalyzeResponse: + if not manager.ready: + raise ModelNotReadyError( + f"Models are not ready (status: {manager.status.value})." + ) + return await manager.analyze(payload.text) diff --git a/app/api/audio.py b/app/api/audio.py new file mode 100644 index 0000000000000000000000000000000000000000..7b22f430c26089cfcdeb312a0bcd7508f619c15c --- /dev/null +++ b/app/api/audio.py @@ -0,0 +1,30 @@ +"""Controlled audio retrieval. + +Serves generated audio by opaque id (never by filesystem path) and 404s once a +file has expired or if the id is malformed. ``Content-Disposition: attachment`` +offers a clean download filename while the same url still streams for replay. +""" + +from __future__ import annotations + +from fastapi import APIRouter, Depends +from fastapi.responses import FileResponse + +from app.api.deps import get_store +from app.audio.store import AudioStore +from app.core.errors import AudioNotFoundError + +router = APIRouter(tags=["audio"]) + + +@router.get("/audio/{audio_id}") +async def get_audio(audio_id: str, store: AudioStore = Depends(get_store)) -> FileResponse: + path = store.path_for(audio_id) + if path is None: + raise AudioNotFoundError("Audio not found or expired.") + return FileResponse( + path, + media_type="audio/mpeg", + filename=f"empathvoice-{audio_id}.mp3", + headers={"Cache-Control": "no-store"}, + ) diff --git a/app/api/deps.py b/app/api/deps.py new file mode 100644 index 0000000000000000000000000000000000000000..443bbef2afcf283c8eaf8f38bdac8fbd89ccb3a8 --- /dev/null +++ b/app/api/deps.py @@ -0,0 +1,25 @@ +"""FastAPI dependency accessors for process-wide singletons. + +The model manager, audio store, and synthesizer are created once in the app +lifespan and stashed on ``app.state``; these helpers expose them to routes. +""" + +from __future__ import annotations + +from fastapi import Request + +from app.audio.store import AudioStore +from app.ml.manager import ModelManager +from app.tts.synth import Synthesizer + + +def get_manager(request: Request) -> ModelManager: + return request.app.state.manager + + +def get_store(request: Request) -> AudioStore: + return request.app.state.audio_store + + +def get_synthesizer(request: Request) -> Synthesizer: + return request.app.state.synthesizer diff --git a/app/api/health.py b/app/api/health.py new file mode 100644 index 0000000000000000000000000000000000000000..23402e16aae18ecaa578bee1ca63dfc4d25c5012 --- /dev/null +++ b/app/api/health.py @@ -0,0 +1,35 @@ +"""Liveness and readiness endpoints. + + * /health — process is up and serving. Always 200. For container liveness. + * /ready — models are loaded and inference can run. 200 when ready, else + 503 with the current model status. For readiness gating. +""" + +from __future__ import annotations + +from fastapi import APIRouter, Depends, Response + +from app.api.deps import get_manager +from app.ml.manager import ModelManager +from app.schemas import HealthResponse, ReadinessResponse + +router = APIRouter(tags=["health"]) + + +@router.get("/health", response_model=HealthResponse) +async def health() -> HealthResponse: + return HealthResponse(status="ok") + + +@router.get("/ready", response_model=ReadinessResponse) +async def ready( + response: Response, manager: ModelManager = Depends(get_manager) +) -> ReadinessResponse: + if not manager.ready: + response.status_code = 503 + return ReadinessResponse( + ready=manager.ready, + model_status=manager.status.value, + device=manager.device, + detail=manager.detail, + ) diff --git a/app/api/synthesize.py b/app/api/synthesize.py new file mode 100644 index 0000000000000000000000000000000000000000..7c097799145c8ff38d824be997b5c484befca438 --- /dev/null +++ b/app/api/synthesize.py @@ -0,0 +1,60 @@ +"""Speech-synthesis endpoint. + +Runs the same analysis as /analyze, converts the prosody parameters into +edge-tts controls, injects clause pauses, synthesizes audio, and stores it under +a temporary id. Returns the audio url plus the analysis that produced it, so the +client never has to call /analyze separately for a one-shot generation. +""" + +from __future__ import annotations + +from fastapi import APIRouter, Depends + +from app.api.deps import get_manager, get_store, get_synthesizer +from app.audio.store import AudioStore +from app.core.config import get_settings +from app.core.errors import InvalidRequestError, ModelNotReadyError +from app.ml.manager import ModelManager +from app.schemas import SynthesizeRequest, SynthesizeResponse +from app.tts.pause_injection import inject_pauses +from app.tts.synth import Synthesizer +from app.tts.voices import VALID_VOICE_IDS + +router = APIRouter(tags=["synthesis"]) + + +@router.post("/synthesize", response_model=SynthesizeResponse) +async def synthesize( + payload: SynthesizeRequest, + manager: ModelManager = Depends(get_manager), + store: AudioStore = Depends(get_store), + synthesizer: Synthesizer = Depends(get_synthesizer), +) -> SynthesizeResponse: + settings = get_settings() + + if not manager.ready: + raise ModelNotReadyError(f"Models are not ready (status: {manager.status.value}).") + + voice = payload.voice or settings.default_voice + if voice not in VALID_VOICE_IDS: + raise InvalidRequestError(f"Unknown voice '{voice}'.") + + analysis = await manager.analyze(payload.text, expressiveness=payload.expressiveness) + prosody = analysis.prosody + + text_for_tts = inject_pauses(payload.text, prosody.pause_level) + audio = await synthesizer.synthesize( + text=text_for_tts, + voice=voice, + rate=f"{prosody.rate_pct:+.0f}%", + pitch=f"{prosody.pitch_hz:+.0f}Hz", + volume=f"{prosody.energy_pct:+.0f}%", + ) + + audio_id = store.save(audio) + return SynthesizeResponse( + audio_id=audio_id, + audio_url=f"/api/audio/{audio_id}", + expires_in_seconds=settings.audio_ttl_seconds, + analysis=analysis, + ) diff --git a/app/api/voices.py b/app/api/voices.py new file mode 100644 index 0000000000000000000000000000000000000000..b027c2d271cda09b51225df6abaa784ee42c3b6e --- /dev/null +++ b/app/api/voices.py @@ -0,0 +1,16 @@ +"""Available voices endpoint for the frontend voice picker.""" + +from __future__ import annotations + +from fastapi import APIRouter + +from app.core.config import get_settings +from app.schemas import VoicesResponse +from app.tts.voices import VOICES + +router = APIRouter(tags=["voices"]) + + +@router.get("/voices", response_model=VoicesResponse) +async def list_voices() -> VoicesResponse: + return VoicesResponse(default=get_settings().default_voice, voices=VOICES) diff --git a/app/audio/__init__.py b/app/audio/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/audio/store.py b/app/audio/store.py new file mode 100644 index 0000000000000000000000000000000000000000..cf1e98cd32dd39ad2f8f6f5f1205dd0db2b1f457 --- /dev/null +++ b/app/audio/store.py @@ -0,0 +1,104 @@ +"""Temporary, TTL-based audio storage. + +Design goals (no Redis/Celery, nothing to persist across restarts): + * files are addressed by an opaque uuid id, never by caller-supplied paths; + * a file stays retrievable for ``ttl_seconds`` (replay + repeated downloads), + i.e. it is NOT deleted on first download; + * expiry is derived from file mtime, so no in-memory index must survive; + * cleanup happens (a) once at startup — wiping any leftovers from a previous + run — and (b) opportunistically, rate-limited, during normal requests. + +This is intentionally simple and self-contained; it is the entire "background +processing" footprint of the app. +""" + +from __future__ import annotations + +import logging +import time +import uuid +from pathlib import Path + +logger = logging.getLogger(__name__) + +_UUID_HEX = frozenset("0123456789abcdef-") +_SWEEP_MIN_INTERVAL_S = 30.0 # don't scan the dir more often than this + + +class AudioStore: + def __init__(self, directory: Path, ttl_seconds: int) -> None: + self._dir = Path(directory) + self._ttl = ttl_seconds + self._last_sweep = 0.0 + self._dir.mkdir(parents=True, exist_ok=True) + + # --- lifecycle ---------------------------------------------------------- + + def purge_all(self) -> int: + """Delete every stored file. Called at startup (no cross-run persistence).""" + removed = 0 + for f in self._dir.glob("*.mp3"): + try: + f.unlink() + removed += 1 + except OSError: + pass + if removed: + logger.info("Startup cleanup removed %d leftover audio file(s)", removed) + return removed + + # --- write / read ------------------------------------------------------- + + def save(self, data: bytes) -> str: + self._maybe_sweep() + audio_id = uuid.uuid4().hex + (self._dir / f"{audio_id}.mp3").write_bytes(data) + return audio_id + + def path_for(self, audio_id: str) -> Path | None: + """Return the file path if the id is valid, present, and unexpired.""" + self._maybe_sweep() + if not self._is_valid_id(audio_id): + return None + path = self._dir / f"{audio_id}.mp3" + if not path.is_file(): + return None + if self._is_expired(path): + self._safe_unlink(path) + return None + return path + + # --- cleanup ------------------------------------------------------------ + + def _maybe_sweep(self) -> None: + now = time.time() + if now - self._last_sweep < _SWEEP_MIN_INTERVAL_S: + return + self._last_sweep = now + for f in self._dir.glob("*.mp3"): + if self._is_expired(f): + self._safe_unlink(f) + + def _is_expired(self, path: Path) -> bool: + try: + return (time.time() - path.stat().st_mtime) > self._ttl + except OSError: + return False + + @staticmethod + def _safe_unlink(path: Path) -> None: + try: + path.unlink() + except OSError: + pass + + @staticmethod + def _is_valid_id(audio_id: str) -> bool: + # Reject anything that isn't a bare uuid hex -> no path traversal. + if not audio_id or not set(audio_id) <= _UUID_HEX: + return False + try: + uuid.UUID(hex=audio_id) + return True + except ValueError: + return False diff --git a/app/config.py b/app/config.py deleted file mode 100644 index 0de38d8e7de7513c3806a1a8c1d4c07c5d282f34..0000000000000000000000000000000000000000 --- a/app/config.py +++ /dev/null @@ -1,15 +0,0 @@ -from pathlib import Path - -VOICE = "en-IN-NeerjaNeural" - -OUT_DIR = Path("audio_outputs") -OUT_DIR.mkdir(exist_ok=True) - -PROSODY_KEYS = ["pitch", "rate", "energy", "pauses"] - -PROSODY_CLAMPS = { - "pitch_hz": 40.0, - "rate_pct": 35.0, - "energy_pct": 30.0, - "pause_gain": 0.45, -} \ No newline at end of file diff --git a/app/core/__init__.py b/app/core/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/core/config.py b/app/core/config.py new file mode 100644 index 0000000000000000000000000000000000000000..f43232372ab60ca74bc8938effc57320d3efef23 --- /dev/null +++ b/app/core/config.py @@ -0,0 +1,52 @@ +"""Centralized, environment-driven configuration. + +Every tunable the app needs lives here as a single `Settings` object, read once +at import and injected where needed. Values come from environment variables +(prefix ``EMPATHVOICE_``) or an optional ``.env`` file; all have defaults, so +the app runs with zero configuration. +""" + +from __future__ import annotations + +from functools import lru_cache +from pathlib import Path + +from pydantic import Field +from pydantic_settings import BaseSettings, SettingsConfigDict + + +class Settings(BaseSettings): + model_config = SettingsConfigDict( + env_prefix="EMPATHVOICE_", + env_file=".env", + env_file_encoding="utf-8", + extra="ignore", + ) + + # --- Server --- + host: str = "127.0.0.1" + port: int = 8000 + + # --- Models --- + emotion_model: str = "SamLowe/roberta-base-go_emotions" + vad_model: str = "RobroKools/vad-bert" + # None => auto-detect (cuda if available else cpu). Set "cpu"/"cuda" to force. + device: str | None = None + inference_concurrency: int = Field(default=1, ge=1, le=8) + + # --- Audio --- + audio_dir: Path = Path("audio_outputs") + audio_ttl_seconds: int = Field(default=3600, ge=1) + default_voice: str = "en-IN-NeerjaNeural" + + # --- Limits --- + max_text_chars: int = Field(default=2000, ge=1) + + # --- Logging --- + log_level: str = "INFO" + + +@lru_cache +def get_settings() -> Settings: + """Return the process-wide settings singleton.""" + return Settings() diff --git a/app/core/errors.py b/app/core/errors.py new file mode 100644 index 0000000000000000000000000000000000000000..45111fac53fc849a298b3870b3bc9b121171a76b --- /dev/null +++ b/app/core/errors.py @@ -0,0 +1,61 @@ +"""Application error types and their HTTP translation. + +Routes raise these semantic errors; a single set of handlers turns them into +consistent JSON responses ``{"error": {"code", "message"}}`` with the right +status code. This keeps raw tracebacks out of responses and gives the frontend +a stable error shape to render. +""" + +from __future__ import annotations + +from fastapi import FastAPI, Request +from fastapi.responses import JSONResponse + + +class AppError(Exception): + """Base class for expected, client-facing errors.""" + + status_code: int = 500 + code: str = "internal_error" + + def __init__(self, message: str) -> None: + super().__init__(message) + self.message = message + + +class InvalidRequestError(AppError): + status_code = 400 + code = "invalid_request" + + +class ModelNotReadyError(AppError): + status_code = 503 + code = "model_not_ready" + + +class SynthesisError(AppError): + status_code = 502 + code = "synthesis_failed" + + +class AudioNotFoundError(AppError): + status_code = 404 + code = "audio_not_found" + + +def _error_response(status_code: int, code: str, message: str) -> JSONResponse: + return JSONResponse( + status_code=status_code, + content={"error": {"code": code, "message": message}}, + ) + + +def register_exception_handlers(app: FastAPI) -> None: + @app.exception_handler(AppError) + async def _handle_app_error(_: Request, exc: AppError) -> JSONResponse: + return _error_response(exc.status_code, exc.code, exc.message) + + @app.exception_handler(Exception) + async def _handle_unexpected(_: Request, exc: Exception) -> JSONResponse: + # Last resort: never leak a traceback to the client. + return _error_response(500, "internal_error", "An unexpected error occurred.") diff --git a/app/core/logging.py b/app/core/logging.py new file mode 100644 index 0000000000000000000000000000000000000000..b760659871ee93656c5cb3fa5a25a121594156a4 --- /dev/null +++ b/app/core/logging.py @@ -0,0 +1,19 @@ +"""Minimal, dependency-free logging setup. + +One place configures the root logger so every module can simply call +``logging.getLogger(__name__)`` and get consistent, timestamped output. +""" + +from __future__ import annotations + +import logging + + +def configure_logging(level: str = "INFO") -> None: + logging.basicConfig( + level=getattr(logging, level.upper(), logging.INFO), + format="%(asctime)s %(levelname)-8s %(name)s | %(message)s", + datefmt="%H:%M:%S", + ) + # edge-tts / urllib3 are chatty at DEBUG; keep them at WARNING. + logging.getLogger("edge_tts").setLevel(logging.WARNING) diff --git a/app/emotion/__init__.py b/app/emotion/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/emotion/fusion.py b/app/emotion/fusion.py new file mode 100644 index 0000000000000000000000000000000000000000..37ca4690852e70882ec56d04358153bba8dbaa35 --- /dev/null +++ b/app/emotion/fusion.py @@ -0,0 +1,59 @@ +"""Confidence-adaptive fusion of the discrete and continuous prosody shifts. + +The blend is unchanged from the original (a per-dimension weighted *arithmetic* +combination — the original docstring mislabelled it a "geometric mean"; the +README's math is the correct description). + +One technically justified refinement (Stage 2, #1): the confidence term now +ignores the ``neutral`` label. GoEmotions assigns neutral text a high +``neutral`` probability, whose prosody row is all zeros; using it as confidence +made the (zero) discrete branch dominate and suppressed the VAD branch, flat- +tening neutral/ambiguous delivery. Excluding neutral lets such text lean on the +continuous branch as the hybrid design intends. When ``neutral_index`` is None +the behaviour is identical to the original. + + c = (max_i, i != neutral, p_i) ** kappa # confidence (neutral excluded) + w_disc = c * alpha_priors # per-dimension discrete weight + w_cont = 1 - w_disc + S_final = w_disc * (G_disc * S_disc) + w_cont * (G_cont * S_cont) +""" + +from __future__ import annotations + +import numpy as np + +ALPHA_PRIORS = np.array([0.62, 0.50, 0.52, 0.55]) +DISC_GAIN = np.array([1.35, 1.35, 1.35, 1.20]) +CONT_GAIN = np.array([0.80, 0.80, 0.80, 0.75]) + + +def fuse( + s_disc: np.ndarray, + s_cont: np.ndarray, + emotion_probs: np.ndarray, + kappa: float = 1.5, + neutral_index: int | None = None, +) -> np.ndarray: + """Fuse discrete and continuous shifts with a confidence-adaptive blend. + + If ``neutral_index`` is given, that label is excluded from the confidence + term (see module docstring). Falls back to the plain max if neutral is the + only label present. + """ + if neutral_index is None: + top_prob = float(np.max(emotion_probs)) + else: + mask = np.ones(len(emotion_probs), dtype=bool) + mask[neutral_index] = False + non_neutral = emotion_probs[mask] + top_prob = float(np.max(non_neutral)) if non_neutral.size else float(np.max(emotion_probs)) + + confidence = top_prob**kappa + + w_disc = confidence * ALPHA_PRIORS + w_cont = 1.0 - w_disc + + s_disc_eff = DISC_GAIN * s_disc + s_cont_eff = CONT_GAIN * s_cont + + return w_disc * s_disc_eff + w_cont * s_cont_eff diff --git a/app/emotion/pipeline.py b/app/emotion/pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..b6e7a27ed0706ec090b23b5d71ca199de6c9c308 --- /dev/null +++ b/app/emotion/pipeline.py @@ -0,0 +1,89 @@ +"""End-to-end emotion -> prosody orchestration (pure, synchronous). + +This is the heart of the system and is deliberately free of torch, FastAPI, and +I/O: it takes already-loaded model objects (anything exposing ``infer`` / an +``EmotionModel`` with ``.labels``) plus the prebuilt weight matrix, and returns +the full analysis. That makes it unit-testable with lightweight fakes and no +model downloads. +""" + +from __future__ import annotations + +from typing import Protocol + +import numpy as np + +from app.emotion.fusion import fuse +from app.emotion.prosody import process_prosody +from app.emotion.vad_mapping import compute_continuous_shift +from app.emotion.weights import compute_discrete_shift +from app.schemas import AnalyzeResponse, EmotionEstimate, VADEstimate + + +class _Infers(Protocol): + def infer(self, text: str) -> np.ndarray: ... + + +def _build_explanation(emotions: list[EmotionEstimate], prosody) -> str: + top = emotions[0].label if emotions else "neutral" + + def describe(value: float, up: str, down: str, unit: str) -> str | None: + if abs(value) < 1e-6: + return None + direction = up if value > 0 else down + return f"{direction} {abs(value):.0f}{unit}" + + parts = [ + p for p in ( + describe(prosody.pitch_hz, "higher pitch", "lower pitch", " Hz"), + describe(prosody.rate_pct, "faster rate", "slower rate", "%"), + describe(prosody.energy_pct, "more energy", "less energy", "%"), + ) if p + ] + pace = "more pauses" if prosody.pause_level > 0.55 else ( + "fewer pauses" if prosody.pause_level < 0.45 else "balanced pauses" + ) + parts.append(pace) + detail = ", ".join(parts) if parts else "near-neutral delivery" + return ( + f"Estimated dominant tone '{top}'. Delivery adjusts toward {detail}. " + "These are model estimates, not a definitive reading of emotion." + ) + + +def analyze( + text: str, + emotion_model, + vad_model: _Infers, + weight_matrix: np.ndarray, + expressiveness: float = 1.0, + top_k: int = 5, +) -> AnalyzeResponse: + probs = emotion_model.infer(text) + vad = vad_model.infer(text) + + labels = emotion_model.labels + neutral_index = labels.index("neutral") if "neutral" in labels else None + + s_disc = compute_discrete_shift(probs, weight_matrix) + s_cont = compute_continuous_shift(vad) + s_final = fuse(s_disc, s_cont, probs, neutral_index=neutral_index) + prosody = process_prosody(s_final, expressiveness=expressiveness) + + order = np.argsort(probs)[::-1][:top_k] + top_emotions = [ + EmotionEstimate(label=emotion_model.labels[i], score=round(float(probs[i]), 4)) + for i in order + ] + + return AnalyzeResponse( + text=text, + top_emotions=top_emotions, + vad=VADEstimate( + valence=round(float(vad[0]), 4), + arousal=round(float(vad[1]), 4), + dominance=round(float(vad[2]), 4), + ), + prosody=prosody, + explanation=_build_explanation(top_emotions, prosody), + ) diff --git a/app/emotion/prosody.py b/app/emotion/prosody.py new file mode 100644 index 0000000000000000000000000000000000000000..7c206a215e282ab5ff23000a455687bdeaa10a18 --- /dev/null +++ b/app/emotion/prosody.py @@ -0,0 +1,49 @@ +"""Post-processing: fused prosody vector -> bounded, TTS-ready parameters. + +Scales each fused dimension and clamps it to a safe range. Values are unchanged +from the original implementation. An optional ``expressiveness`` scalar applies a +single global gain to the (signed) deltas *before* clamping, so the emotion +mappings and fusion are untouched — it only dials the overall strength. +""" + +from __future__ import annotations + +import numpy as np + +from app.schemas import ProsodyParameters + +# Clamp bounds (previously in config.py PROSODY_CLAMPS; kept with the logic they +# govern so the mapping is readable in one place). +PITCH_HZ_CLAMP = 40.0 +RATE_PCT_CLAMP = 35.0 +ENERGY_PCT_CLAMP = 30.0 +PAUSE_GAIN = 0.45 + +# Per-dimension pre-scale (unchanged original factors). +PITCH_SCALE = 0.60 +RATE_SCALE = 0.85 +ENERGY_SCALE = 1.00 + + +def process_prosody(fused: np.ndarray, expressiveness: float = 1.0) -> ProsodyParameters: + pitch = np.clip( + expressiveness * PITCH_SCALE * PITCH_HZ_CLAMP * fused[0], + -PITCH_HZ_CLAMP, PITCH_HZ_CLAMP, + ) + rate = np.clip( + expressiveness * RATE_SCALE * RATE_PCT_CLAMP * fused[1], + -RATE_PCT_CLAMP, RATE_PCT_CLAMP, + ) + energy = np.clip( + expressiveness * ENERGY_SCALE * ENERGY_PCT_CLAMP * fused[2], + -ENERGY_PCT_CLAMP, ENERGY_PCT_CLAMP, + ) + # Pause level is centered at 0.5; expressiveness scales the deviation from it. + pause = np.clip(0.5 + expressiveness * PAUSE_GAIN * fused[3], 0.10, 0.92) + + return ProsodyParameters( + pitch_hz=round(float(pitch), 2), + rate_pct=round(float(rate), 2), + energy_pct=round(float(energy), 2), + pause_level=round(float(pause), 3), + ) diff --git a/app/emotion/vad_mapping.py b/app/emotion/vad_mapping.py new file mode 100644 index 0000000000000000000000000000000000000000..fa3d70cb56491c6b722ed477d0d2fee9b16ba83e --- /dev/null +++ b/app/emotion/vad_mapping.py @@ -0,0 +1,29 @@ +"""Continuous affect (VAD) -> prosody mapping. + +Maps valence/arousal/dominance in [0, 1] to the same 4-D prosody space. Values +and transform (center to [-1, 1], tanh nonlinearity) are unchanged from the +original implementation. +""" + +from __future__ import annotations + +import numpy as np + +# Columns: [Valence, Arousal, Dominance]; rows: [pitch, rate, energy, pauses] +W_VAD = np.array( + [ + [0.25, 0.38, -0.18], # pitch + [0.05, 0.58, -0.08], # rate + [0.15, 0.48, 0.22], # energy + [-0.10, -0.55, -0.10], # pauses + ], + dtype=np.float64, +) + + +def compute_continuous_shift(vad_01: np.ndarray, beta: float = 1.35) -> np.ndarray: + """Continuous prosody shift from VAD coordinates in [0, 1].""" + vad_01 = np.clip(np.asarray(vad_01, dtype=np.float64), 0.0, 1.0) + vad_centered = 2.0 * vad_01 - 1.0 + vad_nonlinear = np.tanh(beta * vad_centered) + return W_VAD @ vad_nonlinear diff --git a/app/emotion/weights.py b/app/emotion/weights.py new file mode 100644 index 0000000000000000000000000000000000000000..5987429f03838606d86c01e2eac46492904de3c0 --- /dev/null +++ b/app/emotion/weights.py @@ -0,0 +1,63 @@ +"""Discrete emotion -> prosody mapping (GoEmotions branch). + +Handcrafted weights mapping each of the 28 GoEmotions labels to a 4-D prosody +shift [pitch, rate, energy, pauses]. Values are unchanged from the original +implementation; only the matrix construction has been decoupled from model +import so this module can be loaded and tested without downloading a model. +""" + +from __future__ import annotations + +from collections.abc import Sequence + +import numpy as np + +# Format: [pitch, rate, energy, pauses] +EMOTION_WEIGHTS: dict[str, list[float]] = { + "admiration": [0.15, 0.08, 0.18, -0.10], + "amusement": [0.25, 0.22, 0.20, -0.20], + "excitement": [0.45, 0.42, 0.45, -0.45], + "joy": [0.38, 0.30, 0.35, -0.32], + "pride": [0.12, -0.08, 0.30, -0.05], + "love": [0.15, -0.12, 0.08, 0.10], + "approval": [0.08, 0.05, 0.10, -0.05], + "caring": [0.05, -0.15, 0.05, 0.15], + "gratitude": [0.18, 0.05, 0.15, -0.08], + "optimism": [0.20, 0.12, 0.18, -0.12], + "relief": [0.05, -0.20, -0.10, 0.18], + "anger": [0.15, 0.32, 0.50, -0.38], + "annoyance": [0.05, 0.15, 0.25, -0.12], + "disgust": [-0.12, -0.10, 0.18, 0.20], + "fear": [0.25, 0.28, 0.10, 0.18], + "nervousness": [0.15, 0.18, -0.08, 0.25], + "disappointment": [-0.22, -0.20, -0.18, 0.28], + "disapproval": [-0.08, 0.05, 0.18, 0.10], + "embarrassment": [-0.18, -0.15, -0.22, 0.25], + "grief": [-0.42, -0.45, -0.40, 0.50], + "remorse": [-0.25, -0.22, -0.20, 0.32], + "sadness": [-0.32, -0.30, -0.28, 0.38], + "confusion": [0.12, -0.15, -0.08, 0.25], + "curiosity": [0.18, 0.10, 0.08, 0.05], + "desire": [0.12, -0.05, 0.10, -0.05], + "realization": [0.10, -0.08, 0.05, 0.15], + "surprise": [0.35, 0.12, 0.28, 0.08], + "neutral": [0.0, 0.0, 0.0, 0.0], +} + + +def build_emotion_matrix(labels: Sequence[str]) -> np.ndarray: + """Build the (num_labels x 4) weight matrix aligned to the model's label order. + + Aligning by label *name* (not index) keeps the mapping correct regardless of + how the model orders its labels. Raises if a label has no defined mapping. + """ + try: + rows = [EMOTION_WEIGHTS[label.lower()] for label in labels] + except KeyError as exc: # pragma: no cover - defensive + raise KeyError(f"No prosody weights defined for emotion label: {exc}") from exc + return np.array(rows, dtype=np.float64) + + +def compute_discrete_shift(probs: np.ndarray, weight_matrix: np.ndarray) -> np.ndarray: + """Discrete prosody shift: S_disc = probs @ W_emo.""" + return probs @ weight_matrix diff --git a/app/main.py b/app/main.py index 4977bcf8c55aa9e982390e323ad9b8086fbd19bb..e905ba1a737c591df331cd043fd125590953bf99 100644 --- a/app/main.py +++ b/app/main.py @@ -1,35 +1,89 @@ +"""Application factory and lifespan wiring. + +Startup sequence (distinct, observable stages): + 1. process starts, logging configured, singletons created, audio dir purged; + 2. model loading kicked off in the background (server is already accepting + connections and /health is green); + 3. /ready flips to true once both models finish loading. + +Shutdown performs a final audio cleanup. +""" + +from __future__ import annotations + +import logging +from contextlib import asynccontextmanager +from pathlib import Path + from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import RedirectResponse from fastapi.staticfiles import StaticFiles -from app.services.engine import run_empathy_engine -from app.tts.pause_injection import inject_pauses -import uuid -from pathlib import Path -from app.tts.tts_engine import synthesize +from app.api import analyze, audio, health, synthesize, voices +from app.audio.store import AudioStore +from app.core.config import get_settings +from app.core.errors import register_exception_handlers +from app.core.logging import configure_logging +from app.ml.manager import ModelManager +from app.tts.synth import EdgeTTSSynthesizer -app = FastAPI() +logger = logging.getLogger(__name__) -audio_dir = Path("audio_outputs") -audio_dir.mkdir(exist_ok=True) -@app.post("/speak") -async def speak(text:str): +@asynccontextmanager +async def lifespan(app: FastAPI): + settings = get_settings() + configure_logging(settings.log_level) + logger.info("Starting EmpathVoice") - pitch,rate,energy,pauses = run_empathy_engine(text) - text_for_tts = inject_pauses(text, pauses) + app.state.audio_store = AudioStore(settings.audio_dir, settings.audio_ttl_seconds) + app.state.audio_store.purge_all() # startup cleanup; nothing persists across runs + app.state.synthesizer = EdgeTTSSynthesizer() + app.state.manager = ModelManager(settings) + await app.state.manager.start_loading() # non-blocking; readiness flips later - file=f"audio_outputs/{uuid.uuid4()}.mp3" + yield - await synthesize( - text_for_tts, - file, - rate=f"{rate:+.0f}%", - pitch=f"{pitch:+.0f}Hz", - volume=f"{energy:+.0f}%" + app.state.audio_store.purge_all() + logger.info("EmpathVoice stopped") + + +def create_app() -> FastAPI: + app = FastAPI( + title="EmpathVoice", + version="0.2.0", + summary="Emotion-aware text-to-speech with a transparent prosody pipeline.", + lifespan=lifespan, + ) + + # Dev convenience: allow the Vite dev server origin. Same-origin in prod. + app.add_middleware( + CORSMiddleware, + allow_origins=["http://localhost:5173", "http://127.0.0.1:5173"], + allow_methods=["GET", "POST"], + allow_headers=["*"], ) - return {"audio":file} + register_exception_handlers(app) + + # Liveness/readiness at root (conventional for probes); everything else under /api. + app.include_router(health.router) + for module in (analyze, synthesize, audio, voices): + app.include_router(module.router, prefix="/api") + + # Serve the built React app when present (frontend/dist). API routes and + # /docs are registered first, so they take precedence over this catch-all + # mount. If the frontend isn't built, fall back to the API docs. + dist = Path(__file__).resolve().parent.parent / "frontend" / "dist" + if dist.is_dir(): + app.mount("/", StaticFiles(directory=dist, html=True), name="frontend") + else: + @app.get("/", include_in_schema=False) + async def root() -> RedirectResponse: + return RedirectResponse(url="/docs") + + return app -app.mount("/audio_outputs", StaticFiles(directory="audio_outputs"), name="audio_outputs") -app.mount("/", StaticFiles(directory="app/static", html=True), name="static") \ No newline at end of file +app = create_app() diff --git a/app/ml/__init__.py b/app/ml/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/ml/emotion_model.py b/app/ml/emotion_model.py new file mode 100644 index 0000000000000000000000000000000000000000..899fcecb696b9ecc5ee88c5f0ff9f1a4a1d1f116 --- /dev/null +++ b/app/ml/emotion_model.py @@ -0,0 +1,54 @@ +"""GoEmotions discrete-emotion model wrapper. + +Heavy imports (torch/transformers) happen inside ``load`` so this module — and +anything that imports it — stays importable without the ML stack installed. +The model is placed on the target device and switched to eval mode (dropout +off) so inference is deterministic. +""" + +from __future__ import annotations + +import logging + +import numpy as np + +logger = logging.getLogger(__name__) + + +def _sigmoid(x: np.ndarray) -> np.ndarray: + return 1.0 / (1.0 + np.exp(-np.clip(x, -20.0, 20.0))) + + +class EmotionModel: + def __init__(self, model_name: str) -> None: + self.model_name = model_name + self._tokenizer = None + self._model = None + self._device = "cpu" + self.labels: list[str] = [] + + def load(self, device: str) -> None: + import torch + from transformers import AutoModelForSequenceClassification, AutoTokenizer + + logger.info("Loading emotion model %s on %s", self.model_name, device) + self._tokenizer = AutoTokenizer.from_pretrained(self.model_name) + model = AutoModelForSequenceClassification.from_pretrained(self.model_name) + model.to(device) + model.eval() # disable dropout -> deterministic inference + self._model = model + self._device = device + self.labels = [model.config.id2label[i] for i in range(model.config.num_labels)] + self._torch = torch + + def infer(self, text: str, temperature: float = 1.1) -> np.ndarray: + """Return per-label sigmoid scores (multi-label, not a distribution).""" + if self._model is None: + raise RuntimeError("EmotionModel.infer called before load()") + torch = self._torch + enc = self._tokenizer( + text, return_tensors="pt", truncation=True, max_length=512 + ).to(self._device) + with torch.no_grad(): + logits = self._model(**enc).logits.squeeze(0).cpu().numpy() + return _sigmoid(logits / temperature) diff --git a/app/ml/manager.py b/app/ml/manager.py new file mode 100644 index 0000000000000000000000000000000000000000..ac73ce550a9764baeb8c364afe1ccab59e23cfaf --- /dev/null +++ b/app/ml/manager.py @@ -0,0 +1,100 @@ +"""Model lifecycle, device handling, and inference concurrency. + +Responsibilities, deliberately in one place: + * detect the device once (auto: cuda if available else cpu; overridable); + * load both models exactly once per process, in eval mode, on that device; + * expose a three-state readiness (LOADING -> READY | FAILED) that is distinct + from "the process is up" (health) and from "a request succeeded"; + * run blocking inference off the event loop, with a semaphore bounding how + many inferences touch the shared model instance at once. + +Loading runs in a background thread kicked off at startup, so the server accepts +connections immediately and ``/ready`` flips to true when the models finish. +""" + +from __future__ import annotations + +import asyncio +import enum +import logging + +from starlette.concurrency import run_in_threadpool + +from app.core.config import Settings +from app.emotion import pipeline +from app.emotion.weights import build_emotion_matrix +from app.ml.emotion_model import EmotionModel +from app.ml.vad_model import VADModel +from app.schemas import AnalyzeResponse + +logger = logging.getLogger(__name__) + + +class ModelStatus(str, enum.Enum): + LOADING = "loading" + READY = "ready" + FAILED = "failed" + + +def _resolve_device(override: str | None) -> str: + if override: + return override + try: + import torch + + return "cuda" if torch.cuda.is_available() else "cpu" + except Exception: # torch missing or broken -> degrade to cpu label + return "cpu" + + +class ModelManager: + def __init__(self, settings: Settings) -> None: + self._settings = settings + self.status = ModelStatus.LOADING + self.device: str | None = None + self.detail: str | None = None + self._emotion: EmotionModel | None = None + self._vad: VADModel | None = None + self._weight_matrix = None + self._semaphore = asyncio.Semaphore(settings.inference_concurrency) + + @property + def ready(self) -> bool: + return self.status is ModelStatus.READY + + async def start_loading(self) -> None: + """Kick off model loading in the background; returns immediately.""" + asyncio.create_task(self._load_async()) + + async def _load_async(self) -> None: + try: + await run_in_threadpool(self._load_blocking) + self.status = ModelStatus.READY + logger.info("Models ready on %s", self.device) + except Exception as exc: # noqa: BLE001 - record, don't crash the app + self.status = ModelStatus.FAILED + self.detail = str(exc) + logger.exception("Model loading failed: %s", exc) + + def _load_blocking(self) -> None: + self.device = _resolve_device(self._settings.device) + emotion = EmotionModel(self._settings.emotion_model) + emotion.load(self.device) + vad = VADModel(self._settings.vad_model) + vad.load(self.device) + self._weight_matrix = build_emotion_matrix(emotion.labels) + self._emotion = emotion + self._vad = vad + + async def analyze(self, text: str, expressiveness: float = 1.0) -> AnalyzeResponse: + if not self.ready: + raise RuntimeError("Models are not ready") + async with self._semaphore: + return await run_in_threadpool( + pipeline.analyze, + text, + self._emotion, + self._vad, + self._weight_matrix, + expressiveness, + ) diff --git a/app/ml/vad_model.py b/app/ml/vad_model.py new file mode 100644 index 0000000000000000000000000000000000000000..ee851886a2414ae135b0a371924c653cee6178f0 --- /dev/null +++ b/app/ml/vad_model.py @@ -0,0 +1,61 @@ +"""VAD-BERT continuous-affect model wrapper. + +Fixes two correctness issues from the original: + * the model is now moved to the target device (the original left it on CPU + while sending inputs to the GPU — a crash waiting for any CUDA box); + * the model is switched to eval mode so dropout no longer randomizes output. + +The output head is validated to be 3-dimensional (valence, arousal, dominance) +so a mismatched checkpoint fails loudly at load instead of deep inside NumPy. +""" + +from __future__ import annotations + +import logging + +import numpy as np + +logger = logging.getLogger(__name__) + + +def _sigmoid(x: np.ndarray) -> np.ndarray: + return 1.0 / (1.0 + np.exp(-np.clip(x, -20.0, 20.0))) + + +class VADModel: + def __init__(self, model_name: str) -> None: + self.model_name = model_name + self._tokenizer = None + self._model = None + self._device = "cpu" + + def load(self, device: str) -> None: + import torch + from transformers import AutoModelForSequenceClassification, AutoTokenizer + + logger.info("Loading VAD model %s on %s", self.model_name, device) + self._tokenizer = AutoTokenizer.from_pretrained(self.model_name) + model = AutoModelForSequenceClassification.from_pretrained(self.model_name) + n_out = model.config.num_labels + if n_out != 3: + raise ValueError( + f"VAD model '{self.model_name}' has {n_out} outputs; expected 3 " + "(valence, arousal, dominance)." + ) + model.to(device) + model.eval() + self._model = model + self._device = device + self._torch = torch + + def infer(self, text: str, temperature: float = 1.2) -> np.ndarray: + """Return [valence, arousal, dominance], each in [0, 1].""" + if self._model is None: + raise RuntimeError("VADModel.infer called before load()") + torch = self._torch + enc = self._tokenizer( + text, return_tensors="pt", truncation=True, max_length=512 + ).to(self._device) + with torch.no_grad(): + raw = self._model(**enc).logits.squeeze(0).cpu().numpy() + return _sigmoid(raw / temperature) diff --git a/app/models/__pycache__/emotion_model.cpython-312.pyc b/app/models/__pycache__/emotion_model.cpython-312.pyc deleted file mode 100644 index f66b292d60fcc44ebd72a79f7832d108a38d15a8..0000000000000000000000000000000000000000 Binary files a/app/models/__pycache__/emotion_model.cpython-312.pyc and /dev/null differ diff --git a/app/models/__pycache__/vad_model.cpython-312.pyc b/app/models/__pycache__/vad_model.cpython-312.pyc deleted file mode 100644 index 4d88e9494fb7dd748b7fcc819a3b982bd48c0505..0000000000000000000000000000000000000000 Binary files a/app/models/__pycache__/vad_model.cpython-312.pyc and /dev/null differ diff --git a/app/models/emotion_model.py b/app/models/emotion_model.py deleted file mode 100644 index 1dacf3038753ad9541572f2fccdbeab0e4c89677..0000000000000000000000000000000000000000 --- a/app/models/emotion_model.py +++ /dev/null @@ -1,22 +0,0 @@ -import torch -import numpy as np -from transformers import AutoTokenizer, AutoModelForSequenceClassification - -GO_MODEL = "SamLowe/roberta-base-go_emotions" -device = torch.device("cuda" if torch.cuda.is_available() else "cpu") - -tok_go = AutoTokenizer.from_pretrained(GO_MODEL) -mdl_go = AutoModelForSequenceClassification.from_pretrained(GO_MODEL).to(device) - -LABELS_GO = [mdl_go.config.id2label[i] for i in range(mdl_go.config.num_labels)] - -def _sigmoid(x): - return 1.0 / (1.0 + np.exp(-np.clip(x, -20.0, 20.0))) - -@torch.no_grad() -def infer_emotions(text, temperature=1.1): - - enc = tok_go(text, return_tensors="pt", truncation=True, max_length=512).to(device) - logits = mdl_go(**enc).logits.squeeze(0).cpu().numpy() - - return _sigmoid(logits / temperature) \ No newline at end of file diff --git a/app/models/vad_model.py b/app/models/vad_model.py deleted file mode 100644 index db311b6a7c998aba631c03a97f19eee727d53c1e..0000000000000000000000000000000000000000 --- a/app/models/vad_model.py +++ /dev/null @@ -1,24 +0,0 @@ -import torch -import numpy as np -from transformers import AutoTokenizer, AutoModelForSequenceClassification - -VAD_MODEL = "RobroKools/vad-bert" - -device = torch.device("cuda" if torch.cuda.is_available() else "cpu") - -tok_vad = AutoTokenizer.from_pretrained(VAD_MODEL) -mdl_vad = AutoModelForSequenceClassification.from_pretrained(VAD_MODEL) - -def _sigmoid(x): - return 1.0 / (1.0 + np.exp(-np.clip(x, -20.0, 20.0))) - -@torch.no_grad() -def infer_vad(text, temperature=1.2): - - enc = tok_vad(text, return_tensors="pt", truncation=True, max_length=512).to(device) - raw = mdl_vad(**enc).logits.squeeze(0).cpu().numpy() - - vad = _sigmoid(raw / temperature) - - return vad - diff --git a/app/schemas.py b/app/schemas.py new file mode 100644 index 0000000000000000000000000000000000000000..e94f8989dd3d3648f7e0c3adf3b9c3d0fe57d948 --- /dev/null +++ b/app/schemas.py @@ -0,0 +1,116 @@ +"""Request/response contracts for the public API. + +Kept in one module because the surface is small. These models define the +OpenAPI schema, validate input, and give the frontend typed shapes to mirror. + +Terminology note: emotion/VAD numbers are *model estimates*, not calibrated +probabilities or ground-truth assessments of anyone's feelings. Field names and +descriptions reflect that deliberately. +""" + +from __future__ import annotations + +from pydantic import BaseModel, Field, field_validator + +from app.core.config import get_settings + + +def _validate_text(value: str) -> str: + text = value.strip() + if not text: + raise ValueError("text must not be empty") + limit = get_settings().max_text_chars + if len(text) > limit: + raise ValueError(f"text must be at most {limit} characters") + return text + + +# --- Shared sub-models ------------------------------------------------------- + +class EmotionEstimate(BaseModel): + """One discrete emotion label and its (uncalibrated) model score.""" + + label: str + score: float = Field(description="Sigmoid score in [0, 1]; not a calibrated probability.") + + +class VADEstimate(BaseModel): + """Continuous affect estimate, each component in [0, 1].""" + + valence: float + arousal: float + dominance: float + + +class ProsodyParameters(BaseModel): + """Final speech-delivery adjustments applied to the TTS voice.""" + + pitch_hz: float = Field(description="Pitch shift in Hz (signed).") + rate_pct: float = Field(description="Speaking-rate change in percent (signed).") + energy_pct: float = Field(description="Loudness/energy change in percent (signed).") + pause_level: float = Field(description="Pause strength scalar in [0, 1].") + + +# --- /analyze ---------------------------------------------------------------- + +class AnalyzeRequest(BaseModel): + text: str + + _check_text = field_validator("text")(_validate_text) + + +class AnalyzeResponse(BaseModel): + text: str + top_emotions: list[EmotionEstimate] + vad: VADEstimate + prosody: ProsodyParameters + explanation: str = Field( + description="Plain-language summary of how the estimates shaped delivery." + ) + + +# --- /synthesize ------------------------------------------------------------- + +class SynthesizeRequest(BaseModel): + text: str + voice: str | None = Field(default=None, description="Voice id; defaults to server default.") + expressiveness: float = Field( + default=1.0, + ge=0.0, + le=1.5, + description="Global scale on prosody deltas before clamping (0 = flat, 1 = normal).", + ) + + _check_text = field_validator("text")(_validate_text) + + +class SynthesizeResponse(BaseModel): + audio_id: str + audio_url: str + expires_in_seconds: int + analysis: AnalyzeResponse + + +# --- Health / readiness / voices -------------------------------------------- + +class HealthResponse(BaseModel): + status: str = "ok" + + +class ReadinessResponse(BaseModel): + ready: bool + model_status: str = Field(description="loading | ready | failed") + device: str | None = None + detail: str | None = None + + +class Voice(BaseModel): + id: str + label: str + locale: str + gender: str + + +class VoicesResponse(BaseModel): + default: str + voices: list[Voice] diff --git a/app/services/__pycache__/engine.cpython-312.pyc b/app/services/__pycache__/engine.cpython-312.pyc deleted file mode 100644 index 0c64d3d919d22dcf6286ada37f72b4e16903e67c..0000000000000000000000000000000000000000 Binary files a/app/services/__pycache__/engine.cpython-312.pyc and /dev/null differ diff --git a/app/services/engine.py b/app/services/engine.py deleted file mode 100644 index a39a640595cd7a68f4403876f7a2395814830bb1..0000000000000000000000000000000000000000 --- a/app/services/engine.py +++ /dev/null @@ -1,25 +0,0 @@ -from app.models.emotion_model import infer_emotions -from app.models.vad_model import infer_vad - -from app.utils.emotion_weights import compute_S_disc -from app.utils.vad_mapping import compute_S_cont -from app.utils.fusion import fuse - -from app.utils.processing import process_prosody - - -def run_empathy_engine(text): - - probs = infer_emotions(text) - - vad = infer_vad(text) - - S_disc = compute_S_disc(probs) - - S_cont = compute_S_cont(vad) - - S_final = fuse(S_disc,S_cont,probs) - - pitch,rate,energy,pauses = process_prosody(S_final) - - return pitch,rate,energy,pauses \ No newline at end of file diff --git a/app/static/index.html b/app/static/index.html deleted file mode 100644 index 9faf52abc67f08b78c86f1eeb5bf3368ab6772d7..0000000000000000000000000000000000000000 --- a/app/static/index.html +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - Empathy Engine - - - - - -
-
-
-
-
- -
- -
-
- - - - - - -
-
-

Empathy Engine

-

Emotion-aware text to speech

-
-
- -
- - 0 -
- - - -
- -
- -
- - - - - \ No newline at end of file diff --git a/app/static/script.js b/app/static/script.js deleted file mode 100644 index b2220059576da06e225cd8dde8f9a8fcd854eb8c..0000000000000000000000000000000000000000 --- a/app/static/script.js +++ /dev/null @@ -1,36 +0,0 @@ -async function generate() { - const textEl = document.getElementById("text"); - const player = document.getElementById("player"); - - if (!textEl || !player) { - return; - } - - const text = textEl.value.trim(); - if (!text) { - alert("Please enter text first."); - return; - } - - try { - const url = `/speak?text=${encodeURIComponent(text)}`; - const response = await fetch(url, { method: "POST" }); - - if (!response.ok) { - const err = await response.text(); - throw new Error(err || `Request failed with status ${response.status}`); - } - - const payload = await response.json(); - if (!payload.audio) { - throw new Error("Backend did not return an audio path."); - } - - // Cache-bust so repeated generations are always fresh. - player.src = `${payload.audio}?t=${Date.now()}`; - await player.play(); - } catch (error) { - console.error("Generate failed:", error); - alert("Could not generate audio. Check backend logs for details."); - } -} diff --git a/app/static/style.css b/app/static/style.css deleted file mode 100644 index ddce98b5632d2758a43bdc628dcc770e1053e6be..0000000000000000000000000000000000000000 --- a/app/static/style.css +++ /dev/null @@ -1,184 +0,0 @@ -*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } - -:root { - --bg: #0e0d12; - --surface: #16141c; - --surface2: #1e1b28; - --border: rgba(255,255,255,0.07); - --accent: #e8865a; - --accent2: #c45ea0; - --text: #f0ecff; - --muted: #7a748f; - --radius: 18px; -} - -body { - min-height: 100vh; - background: var(--bg); - display: flex; - align-items: center; - justify-content: center; - font-family: 'DM Sans', sans-serif; - color: var(--text); - padding: 24px; - overflow: hidden; -} - -/* ── floating orbs ── */ -.bg-orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; } -.orb { - position: absolute; - border-radius: 50%; - filter: blur(90px); - opacity: .35; - animation: drift 12s ease-in-out infinite alternate; -} -.orb-1 { width: 340px; height: 340px; background: #c45ea0; top: -80px; left: -60px; animation-delay: 0s; } -.orb-2 { width: 260px; height: 260px; background: #e8865a; bottom: -60px; right: -40px; animation-delay: -4s; } -.orb-3 { width: 200px; height: 200px; background: #5e6ac4; top: 50%; left: 55%; animation-delay: -8s; } -@keyframes drift { - from { transform: translate(0, 0) scale(1); } - to { transform: translate(30px, 20px) scale(1.1); } -} - -/* ── card ── */ -.card { - position: relative; - z-index: 1; - width: 100%; - max-width: 560px; - background: var(--surface); - border: 1px solid var(--border); - border-radius: 28px; - padding: 36px; - backdrop-filter: blur(20px); - box-shadow: 0 32px 80px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.04); -} - -/* ── header ── */ -.card-header { - display: flex; - align-items: center; - gap: 16px; - margin-bottom: 28px; -} -.icon-wrap { - width: 48px; height: 48px; - flex-shrink: 0; - background: linear-gradient(135deg, var(--accent2), var(--accent)); - border-radius: 14px; - display: flex; align-items: center; justify-content: center; - color: #fff; -} -.icon-wrap svg { width: 24px; height: 24px; } -h1 { - font-family: 'DM Serif Display', serif; - font-size: 1.6rem; - font-weight: 400; - letter-spacing: -.01em; - line-height: 1; -} -.subtitle { - font-size: .78rem; - color: var(--muted); - margin-top: 4px; - font-weight: 300; - letter-spacing: .04em; - text-transform: uppercase; -} - -/* ── textarea ── */ -.textarea-wrap { - position: relative; - margin-bottom: 20px; -} -textarea { - width: 100%; - background: var(--surface2); - border: 1px solid var(--border); - border-radius: var(--radius); - color: var(--text); - font-family: 'DM Sans', sans-serif; - font-size: .95rem; - font-weight: 300; - line-height: 1.7; - padding: 18px 20px 32px; - resize: none; - outline: none; - transition: border-color .2s; -} -textarea::placeholder { color: var(--muted); } -textarea:focus { border-color: rgba(232,134,90,.4); } -.char-count { - position: absolute; - bottom: 12px; - right: 16px; - font-size: .72rem; - color: var(--muted); - pointer-events: none; -} - -/* ── button ── */ -.generate-btn { - width: 100%; - position: relative; - display: flex; - align-items: center; - justify-content: center; - gap: 10px; - background: linear-gradient(135deg, var(--accent2) 0%, var(--accent) 100%); - border: none; - border-radius: var(--radius); - color: #fff; - font-family: 'DM Sans', sans-serif; - font-size: .95rem; - font-weight: 500; - padding: 15px 24px; - cursor: pointer; - transition: opacity .2s, transform .15s; - overflow: hidden; -} -.generate-btn::before { - content: ''; - position: absolute; - inset: 0; - background: rgba(255,255,255,.12); - opacity: 0; - transition: opacity .2s; -} -.generate-btn:hover::before { opacity: 1; } -.generate-btn:active { transform: scale(.98); } -.generate-btn.loading .btn-text { opacity: .4; } -.generate-btn.loading .btn-icon { display: none; } -.generate-btn.loading .btn-spinner { display: block; } - -.btn-icon { width: 16px; height: 16px; } -.btn-spinner { - display: none; - width: 18px; height: 18px; - border: 2px solid rgba(255,255,255,.3); - border-top-color: #fff; - border-radius: 50%; - animation: spin .7s linear infinite; -} -@keyframes spin { to { transform: rotate(360deg); } } - -/* ── audio player ── */ -.audio-wrap { - opacity: 0; - transform: translateY(8px); - pointer-events: none; - transition: opacity .35s ease, transform .35s ease; - margin-top: 16px; -} -.audio-wrap.visible { - opacity: 1; - transform: translateY(0); - pointer-events: auto; -} -audio { - width: 100%; - border-radius: 12px; - accent-color: var(--accent); - filter: invert(0); -} \ No newline at end of file diff --git a/app/static1/static/index.html b/app/static1/static/index.html deleted file mode 100644 index 5df581c90ccce920ae2735c0701842ca5a89057f..0000000000000000000000000000000000000000 --- a/app/static1/static/index.html +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - Empathy Engine - - - - - -
-
-
-
-
- -
- -
-
- - - - - - -
-
-

Empathy Engine

-

Emotion-aware text to speech

-
-
- -
- - 0 -
- -
- detected tone -
- calm - joyful - somber - urgent - tender -
-
- - - -
-
- - - -
-
- -
- -
- -
- - - - - \ No newline at end of file diff --git a/app/static1/static/script.js b/app/static1/static/script.js deleted file mode 100644 index b2220059576da06e225cd8dde8f9a8fcd854eb8c..0000000000000000000000000000000000000000 --- a/app/static1/static/script.js +++ /dev/null @@ -1,36 +0,0 @@ -async function generate() { - const textEl = document.getElementById("text"); - const player = document.getElementById("player"); - - if (!textEl || !player) { - return; - } - - const text = textEl.value.trim(); - if (!text) { - alert("Please enter text first."); - return; - } - - try { - const url = `/speak?text=${encodeURIComponent(text)}`; - const response = await fetch(url, { method: "POST" }); - - if (!response.ok) { - const err = await response.text(); - throw new Error(err || `Request failed with status ${response.status}`); - } - - const payload = await response.json(); - if (!payload.audio) { - throw new Error("Backend did not return an audio path."); - } - - // Cache-bust so repeated generations are always fresh. - player.src = `${payload.audio}?t=${Date.now()}`; - await player.play(); - } catch (error) { - console.error("Generate failed:", error); - alert("Could not generate audio. Check backend logs for details."); - } -} diff --git a/app/static1/static/style.css b/app/static1/static/style.css deleted file mode 100644 index 86f9087183f75f93433da97ba8f8bea568125fa8..0000000000000000000000000000000000000000 --- a/app/static1/static/style.css +++ /dev/null @@ -1,260 +0,0 @@ -*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } - -:root { - --bg: #0e0d12; - --surface: #16141c; - --surface2: #1e1b28; - --border: rgba(255,255,255,0.07); - --accent: #e8865a; - --accent2: #c45ea0; - --text: #f0ecff; - --muted: #7a748f; - --radius: 18px; -} - -body { - min-height: 100vh; - background: var(--bg); - display: flex; - align-items: center; - justify-content: center; - font-family: 'DM Sans', sans-serif; - color: var(--text); - padding: 24px; - overflow: hidden; -} - -/* ── floating orbs ── */ -.bg-orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; } -.orb { - position: absolute; - border-radius: 50%; - filter: blur(90px); - opacity: .35; - animation: drift 12s ease-in-out infinite alternate; -} -.orb-1 { width: 340px; height: 340px; background: #c45ea0; top: -80px; left: -60px; animation-delay: 0s; } -.orb-2 { width: 260px; height: 260px; background: #e8865a; bottom: -60px; right: -40px; animation-delay: -4s; } -.orb-3 { width: 200px; height: 200px; background: #5e6ac4; top: 50%; left: 55%; animation-delay: -8s; } -@keyframes drift { - from { transform: translate(0, 0) scale(1); } - to { transform: translate(30px, 20px) scale(1.1); } -} - -/* ── card ── */ -.card { - position: relative; - z-index: 1; - width: 100%; - max-width: 560px; - background: var(--surface); - border: 1px solid var(--border); - border-radius: 28px; - padding: 36px; - backdrop-filter: blur(20px); - box-shadow: 0 32px 80px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.04); -} - -/* ── header ── */ -.card-header { - display: flex; - align-items: center; - gap: 16px; - margin-bottom: 28px; -} -.icon-wrap { - width: 48px; height: 48px; - flex-shrink: 0; - background: linear-gradient(135deg, var(--accent2), var(--accent)); - border-radius: 14px; - display: flex; align-items: center; justify-content: center; - color: #fff; -} -.icon-wrap svg { width: 24px; height: 24px; } -h1 { - font-family: 'DM Serif Display', serif; - font-size: 1.6rem; - font-weight: 400; - letter-spacing: -.01em; - line-height: 1; -} -.subtitle { - font-size: .78rem; - color: var(--muted); - margin-top: 4px; - font-weight: 300; - letter-spacing: .04em; - text-transform: uppercase; -} - -/* ── textarea ── */ -.textarea-wrap { - position: relative; - margin-bottom: 16px; -} -textarea { - width: 100%; - background: var(--surface2); - border: 1px solid var(--border); - border-radius: var(--radius); - color: var(--text); - font-family: 'DM Sans', sans-serif; - font-size: .95rem; - font-weight: 300; - line-height: 1.7; - padding: 18px 20px 32px; - resize: none; - outline: none; - transition: border-color .2s; -} -textarea::placeholder { color: var(--muted); } -textarea:focus { border-color: rgba(232,134,90,.4); } -.char-count { - position: absolute; - bottom: 12px; - right: 16px; - font-size: .72rem; - color: var(--muted); - pointer-events: none; -} - -/* ── emotion chips ── */ -.emotion-bar { - display: flex; - align-items: center; - gap: 10px; - margin-bottom: 20px; - flex-wrap: wrap; -} -.emotion-label { - font-size: .7rem; - color: var(--muted); - text-transform: uppercase; - letter-spacing: .06em; - flex-shrink: 0; -} -.emotion-chips { display: flex; gap: 6px; flex-wrap: wrap; } -.chip { - font-size: .72rem; - padding: 4px 12px; - border-radius: 100px; - border: 1px solid var(--border); - color: var(--muted); - background: var(--surface2); - transition: all .25s; -} -.chip.active { - border-color: var(--accent); - color: var(--accent); - background: rgba(232,134,90,.1); -} - -/* ── button ── */ -.generate-btn { - width: 100%; - position: relative; - display: flex; - align-items: center; - justify-content: center; - gap: 10px; - background: linear-gradient(135deg, var(--accent2) 0%, var(--accent) 100%); - border: none; - border-radius: var(--radius); - color: #fff; - font-family: 'DM Sans', sans-serif; - font-size: .95rem; - font-weight: 500; - padding: 15px 24px; - cursor: pointer; - transition: opacity .2s, transform .15s; - overflow: hidden; -} -.generate-btn::before { - content: ''; - position: absolute; - inset: 0; - background: rgba(255,255,255,.12); - opacity: 0; - transition: opacity .2s; -} -.generate-btn:hover::before { opacity: 1; } -.generate-btn:active { transform: scale(.98); } -.generate-btn.loading .btn-text { opacity: .4; } -.generate-btn.loading .btn-icon { display: none; } -.generate-btn.loading .btn-spinner { display: block; } - -.btn-icon { width: 16px; height: 16px; } -.btn-spinner { - display: none; - width: 18px; height: 18px; - border: 2px solid rgba(255,255,255,.3); - border-top-color: #fff; - border-radius: 50%; - animation: spin .7s linear infinite; -} -@keyframes spin { to { transform: rotate(360deg); } } - -/* ── waveform ── */ -.waveform-container { - height: 0; - overflow: hidden; - transition: height .4s ease; - display: flex; - align-items: center; - justify-content: center; -} -.waveform-container.active { height: 56px; } -.waveform { - display: flex; - align-items: center; - gap: 4px; - height: 40px; -} -.waveform span { - display: block; - width: 3px; - border-radius: 99px; - background: linear-gradient(to top, var(--accent2), var(--accent)); - animation: wave 1.2s ease-in-out infinite; - height: 6px; -} -.waveform span:nth-child(1) { animation-delay: 0s; } -.waveform span:nth-child(2) { animation-delay: .08s; } -.waveform span:nth-child(3) { animation-delay: .16s; } -.waveform span:nth-child(4) { animation-delay: .24s; } -.waveform span:nth-child(5) { animation-delay: .32s; } -.waveform span:nth-child(6) { animation-delay: .4s; } -.waveform span:nth-child(7) { animation-delay: .48s; } -.waveform span:nth-child(8) { animation-delay: .56s; } -.waveform span:nth-child(9) { animation-delay: .48s; } -.waveform span:nth-child(10) { animation-delay: .4s; } -.waveform span:nth-child(11) { animation-delay: .32s; } -.waveform span:nth-child(12) { animation-delay: .24s; } -.waveform span:nth-child(13) { animation-delay: .16s; } -.waveform span:nth-child(14) { animation-delay: .08s; } -.waveform span:nth-child(15) { animation-delay: 0s; } - -@keyframes wave { - 0%, 100% { height: 6px; opacity: .4; } - 50% { height: 32px; opacity: 1; } -} - -/* ── audio player ── */ -.audio-wrap { - opacity: 0; - transform: translateY(8px); - pointer-events: none; - transition: opacity .35s ease, transform .35s ease; - margin-top: 16px; -} -.audio-wrap.visible { - opacity: 1; - transform: translateY(0); - pointer-events: auto; -} -audio { - width: 100%; - border-radius: 12px; - accent-color: var(--accent); - filter: invert(0); -} \ No newline at end of file diff --git a/app/tts/__init__.py b/app/tts/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/tts/__pycache__/pause_injection.cpython-312.pyc b/app/tts/__pycache__/pause_injection.cpython-312.pyc deleted file mode 100644 index 45ba61c0a637f47790709af0436876e60917e170..0000000000000000000000000000000000000000 Binary files a/app/tts/__pycache__/pause_injection.cpython-312.pyc and /dev/null differ diff --git a/app/tts/__pycache__/tts_engine.cpython-312.pyc b/app/tts/__pycache__/tts_engine.cpython-312.pyc deleted file mode 100644 index 45e166926bb096bab222a686d2e1cad7dc33bc65..0000000000000000000000000000000000000000 Binary files a/app/tts/__pycache__/tts_engine.cpython-312.pyc and /dev/null differ diff --git a/app/tts/pause_injection.py b/app/tts/pause_injection.py index 353a62c29c58ed6c979ae0210a31d3ed3e913eb5..70900bf5092dd99dc30f968bdf523d8491d369a6 100644 --- a/app/tts/pause_injection.py +++ b/app/tts/pause_injection.py @@ -1,59 +1,62 @@ +"""Intra-sentence pause injection. + +edge-tts does not expose SSML ```` control, so pauses are approximated by +inserting commas at clause boundaries / fixed intervals, scaled by the pause +level. Behaviour is unchanged from the original implementation. +""" + +from __future__ import annotations + import numpy as np CLAUSE_WORDS = frozenset({ - 'but','and','or','because','since','while','although', - 'however','therefore','moreover','so','yet','then', - 'still','also','unfortunately','fortunately','honestly', - 'actually','meanwhile','otherwise','nevertheless','though', - 'instead','perhaps','certainly','definitely','really' + "but", "and", "or", "because", "since", "while", "although", + "however", "therefore", "moreover", "so", "yet", "then", + "still", "also", "unfortunately", "fortunately", "honestly", + "actually", "meanwhile", "otherwise", "nevertheless", "though", + "instead", "perhaps", "certainly", "definitely", "really", }) +_PUNCT = frozenset(".,!?;:-") -def inject_pauses(text, pause_level): +def inject_pauses(text: str, pause_level: float) -> str: text = text.strip() - if not text or pause_level < 0.35: return text words = text.split() - if len(words) < 4: return text # Higher pause level inserts pauses more frequently. - interval = int(np.interp(pause_level,[0.35,0.92],[14,4])) - - min_gap = max(3,interval//2) - - out=[] + interval = int(np.interp(pause_level, [0.35, 0.92], [14, 4])) + min_gap = max(3, interval // 2) - since_pause=0 - - for i,word in enumerate(words): + out: list[str] = [] + since_pause = 0 + for i, word in enumerate(words): out.append(word) + since_pause += 1 - since_pause+=1 - - if i >= len(words)-1: + if i >= len(words) - 1: continue - # Reset if the current token already ends a natural sentence/clause. - if word.rstrip()[-1:] in set('.,!?;:-'): + # Reset if the current token already ends a natural clause/sentence. + if word.rstrip()[-1:] in _PUNCT: since_pause = 0 continue - next_word = words[i+1].lower().strip('.,!?;:') - + next_word = words[i + 1].lower().strip(".,!?;:") at_boundary = next_word in CLAUSE_WORDS and since_pause >= min_gap at_interval = since_pause >= interval and pause_level > 0.65 if at_boundary or at_interval: - - if not out[-1].endswith(","): + # Never stack punctuation: only add a comma if the token doesn't + # already end in some punctuation mark. + if out[-1][-1:] not in _PUNCT: out[-1] = out[-1] + "," + since_pause = 0 - since_pause=0 - - return " ".join(out) \ No newline at end of file + return " ".join(out) diff --git a/app/tts/synth.py b/app/tts/synth.py new file mode 100644 index 0000000000000000000000000000000000000000..a06db347b180d180036f177217ee5418aedb48a5 --- /dev/null +++ b/app/tts/synth.py @@ -0,0 +1,45 @@ +"""Text-to-speech synthesis behind a small interface. + +The ``Synthesizer`` protocol lets tests inject a fake that returns dummy bytes, +so the API and audio-store logic can be exercised without network access or the +edge-tts dependency. ``EdgeTTSSynthesizer`` is the real implementation; it +streams audio chunks and returns the full MP3 as bytes (decoupled from storage). +""" + +from __future__ import annotations + +import logging +from typing import Protocol + +from app.core.errors import SynthesisError + +logger = logging.getLogger(__name__) + + +class Synthesizer(Protocol): + async def synthesize( + self, text: str, voice: str, rate: str, pitch: str, volume: str + ) -> bytes: ... + + +class EdgeTTSSynthesizer: + async def synthesize( + self, text: str, voice: str, rate: str, pitch: str, volume: str + ) -> bytes: + import edge_tts + + try: + communicate = edge_tts.Communicate( + text=text, voice=voice, rate=rate, pitch=pitch, volume=volume + ) + chunks = bytearray() + async for chunk in communicate.stream(): + if chunk["type"] == "audio": + chunks.extend(chunk["data"]) + except Exception as exc: # noqa: BLE001 - surface as a clean 502 + logger.warning("edge-tts synthesis failed: %s", exc) + raise SynthesisError("Speech synthesis failed. Please try again.") from exc + + if not chunks: + raise SynthesisError("Speech synthesis produced no audio.") + return bytes(chunks) diff --git a/app/tts/tts_engine.py b/app/tts/tts_engine.py deleted file mode 100644 index 3c7040634a9ccf9d09c1785b24939dc72a2fcad9..0000000000000000000000000000000000000000 --- a/app/tts/tts_engine.py +++ /dev/null @@ -1,14 +0,0 @@ -import edge_tts -from app.config import VOICE - -async def synthesize(text,path,rate="+0%",pitch="+0Hz",volume="+0%"): - - comm = edge_tts.Communicate( - text=text, - voice=VOICE, - rate=rate, - pitch=pitch, - volume=volume - ) - - await comm.save(path) \ No newline at end of file diff --git a/app/tts/voices.py b/app/tts/voices.py new file mode 100644 index 0000000000000000000000000000000000000000..105cea45855fa329583fe6146e772ab106c1597a --- /dev/null +++ b/app/tts/voices.py @@ -0,0 +1,22 @@ +"""Curated set of edge-tts voices offered by the UI. + +A small, hand-checked list keeps the voice picker predictable and avoids a slow +network call to enumerate the full edge-tts catalogue on every request. Extend +as needed; ids must be valid edge-tts voice names. +""" + +from __future__ import annotations + +from app.schemas import Voice + +VOICES: list[Voice] = [ + Voice(id="en-IN-NeerjaNeural", label="Neerja (Indian English)", locale="en-IN", gender="Female"), + Voice(id="en-IN-PrabhatNeural", label="Prabhat (Indian English)", locale="en-IN", gender="Male"), + Voice(id="en-US-AriaNeural", label="Aria (US English)", locale="en-US", gender="Female"), + Voice(id="en-US-GuyNeural", label="Guy (US English)", locale="en-US", gender="Male"), + Voice(id="en-GB-SoniaNeural", label="Sonia (British English)", locale="en-GB", gender="Female"), + Voice(id="en-GB-RyanNeural", label="Ryan (British English)", locale="en-GB", gender="Male"), + Voice(id="en-AU-NatashaNeural", label="Natasha (Australian English)", locale="en-AU", gender="Female"), +] + +VALID_VOICE_IDS = frozenset(v.id for v in VOICES) diff --git a/app/utils/__pycache__/emotion_weights.cpython-312.pyc b/app/utils/__pycache__/emotion_weights.cpython-312.pyc deleted file mode 100644 index 93f2183a1c18ad5cc38175c3f8df0e5d979510a7..0000000000000000000000000000000000000000 Binary files a/app/utils/__pycache__/emotion_weights.cpython-312.pyc and /dev/null differ diff --git a/app/utils/__pycache__/fusion.cpython-312.pyc b/app/utils/__pycache__/fusion.cpython-312.pyc deleted file mode 100644 index 8c22546a9d6b4e5ae723e99202a002c42d8bd1d7..0000000000000000000000000000000000000000 Binary files a/app/utils/__pycache__/fusion.cpython-312.pyc and /dev/null differ diff --git a/app/utils/__pycache__/processing.cpython-312.pyc b/app/utils/__pycache__/processing.cpython-312.pyc deleted file mode 100644 index 9fd3efb29537a2432eb0248d5501dc777c54f3e5..0000000000000000000000000000000000000000 Binary files a/app/utils/__pycache__/processing.cpython-312.pyc and /dev/null differ diff --git a/app/utils/__pycache__/vad_mapping.cpython-312.pyc b/app/utils/__pycache__/vad_mapping.cpython-312.pyc deleted file mode 100644 index 06d3f8035843dbfc1f9835b94ec763e2046a5f20..0000000000000000000000000000000000000000 Binary files a/app/utils/__pycache__/vad_mapping.cpython-312.pyc and /dev/null differ diff --git a/app/utils/emotion_weights.py b/app/utils/emotion_weights.py deleted file mode 100644 index ec3f5f8660c0a4916c70c9483580a15a199b991d..0000000000000000000000000000000000000000 --- a/app/utils/emotion_weights.py +++ /dev/null @@ -1,60 +0,0 @@ -import numpy as np -from app.models.emotion_model import LABELS_GO - -# Format: [pitch, rate, energy, pauses] -weights_emotions = { - - - "admiration": [ 0.15, 0.08, 0.18, -0.10], - "amusement": [ 0.25, 0.22, 0.20, -0.20], - "excitement": [ 0.45, 0.42, 0.45, -0.45], - "joy": [ 0.38, 0.30, 0.35, -0.32], - "pride": [ 0.12, -0.08, 0.30, -0.05], - "love": [ 0.15, -0.12, 0.08, 0.10], - - - "approval": [ 0.08, 0.05, 0.10, -0.05], - "caring": [ 0.05, -0.15, 0.05, 0.15], - "gratitude": [ 0.18, 0.05, 0.15, -0.08], - "optimism": [ 0.20, 0.12, 0.18, -0.12], - "relief": [ 0.05, -0.20, -0.10, 0.18], - - - "anger": [ 0.15, 0.32, 0.50, -0.38], - "annoyance": [ 0.05, 0.15, 0.25, -0.12], - "disgust": [-0.12, -0.10, 0.18, 0.20], - "fear": [ 0.25, 0.28, 0.10, 0.18], - "nervousness": [ 0.15, 0.18, -0.08, 0.25], - - - "disappointment": [-0.22, -0.20, -0.18, 0.28], - "disapproval": [-0.08, 0.05, 0.18, 0.10], - "embarrassment": [-0.18, -0.15, -0.22, 0.25], - "grief": [-0.42, -0.45, -0.40, 0.50], - "remorse": [-0.25, -0.22, -0.20, 0.32], - "sadness": [-0.32, -0.30, -0.28, 0.38], - - - "confusion": [ 0.12, -0.15, -0.08, 0.25], - "curiosity": [ 0.18, 0.10, 0.08, 0.05], - "desire": [ 0.12, -0.05, 0.10, -0.05], - "realization": [ 0.10, -0.08, 0.05, 0.15], - "surprise": [ 0.35, 0.12, 0.28, 0.08], - - "neutral": [0.0, 0.0, 0.0, 0.0], -} - -# Build weight matrix aligned with model label order -W_emo = np.array( - [weights_emotions[label.lower()] for label in LABELS_GO], - dtype=np.float64 -) - - -def compute_S_disc(probs): - """ - Discrete prosody shift. - - S_disc = probs^T @ W_emo - """ - return probs @ W_emo \ No newline at end of file diff --git a/app/utils/fusion.py b/app/utils/fusion.py deleted file mode 100644 index e61d49bf2c11105b7ed67d00c9cc12572a6c3313..0000000000000000000000000000000000000000 --- a/app/utils/fusion.py +++ /dev/null @@ -1,23 +0,0 @@ -import numpy as np - -ALPHA_PRIORS = np.array([0.62, 0.50, 0.52, 0.55]) - -DISC_GAIN = np.array([1.35,1.35,1.35,1.20]) -CONT_GAIN = np.array([0.80,0.80,0.80,0.75]) - -def fuse(S_disc: np.ndarray, S_cont: np.ndarray, emotion_probs: np.ndarray, kappa: float = 1.5) -> np.ndarray: - """ - Fuses discrete and continuous shift outputs using a weighted geometric mean. - """ - max_prob = np.max(emotion_probs) - - c = max_prob ** kappa - - w_disc = c * ALPHA_PRIORS - w_cont = 1 - w_disc - - S_disc_eff = DISC_GAIN * S_disc - S_cont_eff = CONT_GAIN * S_cont - - S_final = w_disc * S_disc_eff + w_cont * S_cont_eff - return S_final \ No newline at end of file diff --git a/app/utils/processing.py b/app/utils/processing.py deleted file mode 100644 index 030fdefda8f1aa84d39f7d2f043e397918399045..0000000000000000000000000000000000000000 --- a/app/utils/processing.py +++ /dev/null @@ -1,21 +0,0 @@ -import numpy as np -from app.config import PROSODY_CLAMPS - -def process_prosody(p): - - pitch = np.clip(0.60*PROSODY_CLAMPS["pitch_hz"]*p[0], - -PROSODY_CLAMPS["pitch_hz"], - PROSODY_CLAMPS["pitch_hz"]) - - rate = np.clip(0.85*PROSODY_CLAMPS["rate_pct"]*p[1], - -PROSODY_CLAMPS["rate_pct"], - PROSODY_CLAMPS["rate_pct"]) - - energy = np.clip(PROSODY_CLAMPS["energy_pct"]*p[2], - -PROSODY_CLAMPS["energy_pct"], - PROSODY_CLAMPS["energy_pct"]) - - pauses = np.clip(0.5 + PROSODY_CLAMPS["pause_gain"]*p[3], - 0.10,0.92) - - return pitch,rate,energy,pauses \ No newline at end of file diff --git a/app/utils/vad_mapping.py b/app/utils/vad_mapping.py deleted file mode 100644 index d0178b02ac2bf822c247ba3a35759061e411df61..0000000000000000000000000000000000000000 --- a/app/utils/vad_mapping.py +++ /dev/null @@ -1,24 +0,0 @@ -import numpy as np - -# Columns: [Valence, Arousal, Dominance] - -W_vad = np.array([ - [ 0.25, 0.38, -0.18], # pitch - [ 0.05, 0.58, -0.08], # rate - [ 0.15, 0.48, 0.22], # energy - [-0.10, -0.55, -0.10], # pauses -], dtype=np.float64) - - -def compute_S_cont(vad_01, beta=1.35): - """ - Continuous prosody shift from VAD coordinates. - """ - - vad_01 = np.clip(np.asarray(vad_01), 0.0, 1.0) - - vad_centered = 2 * vad_01 - 1 - - vad_nonlinear = np.tanh(beta * vad_centered) - - return W_vad @ vad_nonlinear \ No newline at end of file diff --git a/audio_outputs/20c50eea-0900-4f3c-a1a7-6229474a67af.mp3 b/audio_outputs/20c50eea-0900-4f3c-a1a7-6229474a67af.mp3 deleted file mode 100644 index d8d68da4b2c3032943e6d9a3e14e810a6be238c2..0000000000000000000000000000000000000000 Binary files a/audio_outputs/20c50eea-0900-4f3c-a1a7-6229474a67af.mp3 and /dev/null differ diff --git a/audio_outputs/61b8b8db-dbd8-49ee-8d2f-bea5f075561c.mp3 b/audio_outputs/61b8b8db-dbd8-49ee-8d2f-bea5f075561c.mp3 deleted file mode 100644 index 89b2783a81bdd99562c63299c7956166ff1f95af..0000000000000000000000000000000000000000 Binary files a/audio_outputs/61b8b8db-dbd8-49ee-8d2f-bea5f075561c.mp3 and /dev/null differ diff --git a/audio_outputs/868e769f-54bc-4ab3-8662-3b1d6f6d9cb5.mp3 b/audio_outputs/868e769f-54bc-4ab3-8662-3b1d6f6d9cb5.mp3 deleted file mode 100644 index 4e34fa73065187d5ead6f53d817d7dab978ad5ad..0000000000000000000000000000000000000000 Binary files a/audio_outputs/868e769f-54bc-4ab3-8662-3b1d6f6d9cb5.mp3 and /dev/null differ diff --git a/audio_outputs/9dcc96db-f8a6-4105-bcb8-2a94cfa18a08.mp3 b/audio_outputs/9dcc96db-f8a6-4105-bcb8-2a94cfa18a08.mp3 deleted file mode 100644 index f0dabf38b3becef7bcc72abd31ce03dad82afc86..0000000000000000000000000000000000000000 Binary files a/audio_outputs/9dcc96db-f8a6-4105-bcb8-2a94cfa18a08.mp3 and /dev/null differ diff --git a/audio_outputs/eaa78a25-d300-4d2a-9668-38228393edaa.mp3 b/audio_outputs/eaa78a25-d300-4d2a-9668-38228393edaa.mp3 deleted file mode 100644 index 4e34fa73065187d5ead6f53d817d7dab978ad5ad..0000000000000000000000000000000000000000 Binary files a/audio_outputs/eaa78a25-d300-4d2a-9668-38228393edaa.mp3 and /dev/null differ diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000000000000000000000000000000000000..80cfff31664c1f2d55779feffe953306ef954f37 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,175 @@ +# EmpathVoice — Architecture + +This document explains how EmpathVoice is put together: the request lifecycle, +the component boundaries, the model lifecycle, the audio strategy, and the main +design decisions and their trade-offs. + +## Goals that shaped the design + +1. **Interpretability first.** The emotion→prosody mapping is explicit and + deterministic, so every delivery decision can be traced to model outputs. +2. **Separation of concerns.** HTTP handling, schemas, configuration, model + lifecycle, the analysis pipeline, TTS, and audio storage are independent and + individually testable. +3. **No unnecessary infrastructure.** No database, no task queue, no cache + server. The only background work is a self-contained audio TTL sweep. +4. **Testable without the heavy stack.** The pure pipeline and the API can be + tested with fakes — no model downloads, no network. + +## Component map + +``` +app/ + main.py app factory, lifespan, routing, SPA serving + core/ + config.py Settings (env-driven, one source of truth) + logging.py logging setup + errors.py AppError hierarchy + JSON exception handlers + schemas.py Pydantic request/response contracts (the API surface) + ml/ + emotion_model.py GoEmotions wrapper (lazy heavy imports, eval, device) + vad_model.py VAD-BERT wrapper (device fix, eval, 3-D head check) + manager.py lifecycle: load once, device, readiness, concurrency + emotion/ + weights.py discrete 28×4 mapping + matrix builder + vad_mapping.py continuous VAD→prosody mapping + fusion.py confidence-adaptive fusion (neutral-excluded) + prosody.py scale + clamp → bounded TTS parameters + pipeline.py pure orchestration: text → full analysis + tts/ + pause_injection.py clause/interval comma insertion + synth.py Synthesizer protocol + EdgeTTSSynthesizer + voices.py curated voice list + audio/ + store.py TTL, id-based storage with cleanup + api/ + deps.py accessors for the lifespan singletons + health.py analyze.py synthesize.py audio.py voices.py +``` + +The dependency direction is one-way: `api` → `ml`/`emotion`/`tts`/`audio` → +`core`/`schemas`. The `emotion/pipeline.py` core imports none of torch, FastAPI, +or I/O — it takes already-loaded model objects, which is what makes it unit- +testable with lightweight fakes. + +## Request lifecycle + +### `POST /api/synthesize` + +``` +client + → FastAPI route (validate SynthesizeRequest: non-empty, ≤ max chars) + → check readiness (503 model_not_ready if models aren't loaded) + → validate voice against the curated list (400 invalid_request) + → ModelManager.analyze(text): + acquire inference semaphore + run_in_threadpool(pipeline.analyze): # off the event loop + probs = EmotionModel.infer(text) # torch, no_grad, eval + vad = VADModel.infer(text) + s_disc = probs @ W_emo + s_cont = W_vad @ tanh(β·(2·vad−1)) + s_final = fuse(s_disc, s_cont, probs, neutral_index) + prosody = clamp(scale(s_final)) + → AnalyzeResponse (emotions, vad, prosody, explanation) + → inject_pauses(text, prosody.pause_level) + → EdgeTTSSynthesizer.synthesize(...) → mp3 bytes # async, external service + → AudioStore.save(bytes) → audio_id + → SynthesizeResponse(audio_id, audio_url=/api/audio/, ttl, analysis) +``` + +`/api/analyze` is the same up to the `AnalyzeResponse` and returns there, so the +frontend can preview the analysis without paying for synthesis. + +### Why inference runs in a threadpool + +Model inference is synchronous, CPU/GPU-bound work. Running it directly in an +`async` endpoint would block the event loop and serialize all requests behind +each inference. It is dispatched with `run_in_threadpool`, and an +`asyncio.Semaphore` (size `INFERENCE_CONCURRENCY`, default 1) bounds how many +inferences touch the shared model instance at once — keeping the event loop +responsive without oversubscribing a single shared model. + +## Model lifecycle and readiness + +Three states are kept deliberately distinct: + +- **Process health** (`/health`) — the server is up. Always 200. Suitable for a + liveness probe. +- **Model readiness** (`/ready`) — the models have finished loading. Returns 200 + when ready, otherwise 503 with `model_status` ∈ {`loading`, `failed`} plus the + resolved device and any error detail. Suitable for a readiness probe. +- **Request success** — an individual `/api/analyze` or `/api/synthesize` call. + +At startup, the lifespan creates the singletons and kicks off model loading in a +**background thread**, so the server accepts connections immediately and +`/ready` flips to `ready` once loading completes. If loading fails (e.g. no +network to download weights), the status becomes `failed` with a detail message +rather than crashing the process; the UI surfaces this. + +The models are loaded **once per process**, placed on the resolved device +(`cuda` if available else `cpu`, overridable), and switched to `eval()` so +dropout is disabled and inference is deterministic. The VAD model's output head +is validated to be 3-dimensional at load, turning a would-be deep NumPy error +into a clear startup failure. + +## The fusion math + +Given the discrete shift `s_disc`, continuous shift `s_cont`, and discrete +scores `p`: + +``` +c = (max_{i ≠ neutral} p_i) ^ κ # confidence, neutral excluded +w_disc = c · α # per-dimension discrete weight +w_cont = 1 − w_disc +s_final = w_disc · (G_disc · s_disc) + w_cont · (G_cont · s_cont) +``` + +`α` (per-dimension priors), `G_disc`/`G_cont` (per-dimension gains), and `κ` are +fixed constants. High discrete confidence weights the categorical branch; low +confidence falls back toward the smoother VAD branch. Excluding `neutral` from +`c` prevents confidently-neutral text from suppressing the VAD branch (its +discrete prosody row is all zeros). + +The final vector is scaled per dimension and clamped to `±40 Hz` (pitch), +`±35 %` (rate), `±30 %` (energy), and `[0.10, 0.92]` (pause level) before being +handed to edge-tts. + +## Audio storage strategy + +Generated audio is temporary and self-managing — no database, no object store: + +- Files are addressed by an **opaque uuid id**, never by caller-supplied paths; + the retrieval endpoint rejects anything that isn't a bare uuid, so there is no + path traversal. +- A file remains retrievable for `AUDIO_TTL_SECONDS` (default 1 hour), supporting + replay and repeated downloads — it is **not** deleted on first download. +- Expiry is derived from file mtime, so no in-memory index needs to survive. +- Cleanup happens at **startup** (wiping any leftovers from a previous run, since + nothing is meant to persist) and **opportunistically** during requests, + rate-limited so the directory isn't scanned on every call. + +This is the entire "background processing" footprint of the app. + +## Frontend + +A React + TypeScript + Vite single-page app. State is handled with plain hooks +(no external state library). The API client is a thin typed wrapper whose types +mirror the backend schemas. Analysis is previewed live via a debounced +`/api/analyze` call as the user types; synthesis is an explicit action that +returns both the audio and the analysis that produced it. In development, Vite +proxies `/api` and the probe routes to the backend; in production, FastAPI serves +the built assets, so the app is same-origin in both cases. + +## Notable design decisions and trade-offs + +- **FastAPI retained, reorganized.** The original stack was sound; the work was + boundaries and lifecycle, not a rewrite. +- **`/api` prefix + SPA at `/`.** Clean separation between the API and the + single-page app, with probes at the root. +- **Pure pipeline core.** Keeping `pipeline.analyze` free of torch/HTTP is what + makes the whole thing testable without model downloads; the cost is passing + model objects in explicitly rather than importing singletons. +- **Heuristic prosody kept.** The hand-tuned mapping is the project's + interpretable contribution. It is refined (neutral-aware fusion, pause + robustness) but not replaced by a learned model, which would change the + project's nature and require data and evaluation. diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000000000000000000000000000000000000..3179e1e6ebdcdc4f718326fcaafd330a8df012bc --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,18 @@ + + + + + + EmpathVoice — Emotion-aware TTS + + + + + +
+ + + diff --git a/frontend/package-lock.json b/frontend/package-lock.json new file mode 100644 index 0000000000000000000000000000000000000000..b8ea1bf4882975e93c2e7a534177f2f7419b5756 --- /dev/null +++ b/frontend/package-lock.json @@ -0,0 +1,1864 @@ +{ + "name": "empathvoice-frontend", + "version": "0.2.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "empathvoice-frontend", + "version": "0.2.0", + "dependencies": { + "react": "^18.3.1", + "react-dom": "^18.3.1" + }, + "devDependencies": { + "@types/react": "^18.3.12", + "@types/react-dom": "^18.3.1", + "@vitejs/plugin-react": "^4.3.4", + "typescript": "^5.6.3", + "vite": "^6.0.7" + } + }, + "node_modules/@babel/code-frame": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", + "integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-validator-identifier": "^7.29.7", + "js-tokens": "^4.0.0", + "picocolors": "^1.1.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/compat-data": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.29.7.tgz", + "integrity": "sha512-locTkQyKvwIEgBzVrn8693ebc97F2U8ZHjbXwDXJ5Fn2TCpNwTlKcaKLkdHop5c/icOFE7qt7Q9JC5hnKNa6Gg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/core": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.13.tgz", + "integrity": "sha512-j1nvOQCZYSgp7HLmisnCXFTpVvFODiijQ9QHkORfGKWH6YDtskTEeCJS7eV545GZ9UBzrq0e2xsOd5QQ5PjIqw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/generator": "^7.29.13", + "@babel/helper-compilation-targets": "^7.29.13", + "@babel/helper-module-transforms": "^7.29.13", + "@babel/helpers": "^7.29.13", + "@babel/parser": "^7.29.13", + "@babel/template": "^7.29.7", + "@babel/traverse": "^7.29.13", + "@babel/types": "^7.29.11", + "@jridgewell/remapping": "^2.3.5", + "convert-source-map": "^2.0.0", + "debug": "^4.1.0", + "gensync": "^1.0.0-beta.2", + "json5": "^2.2.3", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/babel" + } + }, + "node_modules/@babel/generator": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.13.tgz", + "integrity": "sha512-T5FRo+RzVHvGjWOuF1Ljc44b+NXAOazodHkGUHp4I3zCkQ4/sNVJm56h1S278LMR0bY5xBhztGziSbli8zObIw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.13", + "@babel/types": "^7.29.11", + "@jridgewell/gen-mapping": "^0.3.12", + "@jridgewell/trace-mapping": "^0.3.28", + "jsesc": "^3.0.2" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-compilation-targets": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.29.13.tgz", + "integrity": "sha512-8WxJ4/Vmes3ghacj8VOJy3NW8eyHiFY/4thU/LSBuBE470+igjR/j1ZTNn8fV5VdNrLx6iXUwig526UdOvfP0w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/compat-data": "^7.29.7", + "@babel/helper-validator-option": "^7.29.7", + "browserslist": "^4.24.0", + "lru-cache": "^5.1.1", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-globals": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.29.7.tgz", + "integrity": "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-module-imports": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.29.7.tgz", + "integrity": "sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/traverse": "^7.29.7", + "@babel/types": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-module-transforms": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.29.13.tgz", + "integrity": "sha512-/U96wOz+SCoZ7Da/8kjDGltcNY280JPQcRNPK0Hk3PTbdpaiBDQImtC6JsbVwb1HGMr3usZQU2WsWVjhYNmRzw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-module-imports": "^7.29.7", + "@babel/helper-validator-identifier": "^7.29.7", + "@babel/traverse": "^7.29.13" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, + "node_modules/@babel/helper-plugin-utils": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.29.7.tgz", + "integrity": "sha512-G7sHYigPY17oO5SYWnfD/0MTBwVR781S/JI643e/JhUYgVgWE/61SoW3NH9KWUKyKq5LVh3npif99Wkt6j86Jw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-string-parser": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.13.tgz", + "integrity": "sha512-fWegr+WsEsiMVW4KUNdIIzzMTZSzNiqhy0//6+2MRi2d5NFNsL/AYwBQW8eBnRbTBVRnDVzjaJEUqKaCWjMMdQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", + "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-option": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.29.7.tgz", + "integrity": "sha512-N9ZErrD+yW5geCDtBqnOoxmR8+tNKiGuxKlDpuJxfsqpa2dFcexaziGAE/qoHLiDDreVNMupxGmSoNlyvsA3gw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helpers": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.29.13.tgz", + "integrity": "sha512-laoRpD/kO/iA4CDlgJbixHekg7oPvWALK0PQyK3Ob2I2njZRvVAD77RfWCIImtqWCq6KijoBoZK7bp/HlTWASQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/template": "^7.29.7", + "@babel/types": "^7.29.11" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/parser": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.13.tgz", + "integrity": "sha512-fJM50YYjlTiBhgdkGmC1tBpv+FMAyo4annf2X6Aks+0yRlaiVkYW/3f07xAfVVkYIoZ9fFZp+mEThUFnuybhkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.29.11" + }, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@babel/plugin-transform-react-jsx-self": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.29.7.tgz", + "integrity": "sha512-TL0hMc9xzy86VD31nUiwzd5otRAcyEPcsegCxolO0PvcXuH1v0kECe/UIznYFihpkvU5wg/jk4v0TTEFfm53fw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-plugin-utils": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-react-jsx-source": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.29.7.tgz", + "integrity": "sha512-06IyK09H3wi4cGbhDBwp5gUGo0IKtnYa8tyTiephirPCK6fbobVGiXMMI5zLQ4aKEYP3wZ3ArU44o+8KMrSG/Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-plugin-utils": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/template": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz", + "integrity": "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/parser": "^7.29.7", + "@babel/types": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/traverse": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.13.tgz", + "integrity": "sha512-0ve0xMlFA73dgY1oyJRY6RoW+/bncdcOQqg6jjYcVfXBK90OdLXjm9R6lmRetdZVrPjXkKIoMVBqYFPjcAlZ4Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/generator": "^7.29.13", + "@babel/helper-globals": "^7.29.7", + "@babel/parser": "^7.29.13", + "@babel/template": "^7.29.7", + "@babel/types": "^7.29.11", + "debug": "^4.3.1" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/types": { + "version": "7.29.11", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.11.tgz", + "integrity": "sha512-WCsemW40Cpc6gouC1SrY6PBaZ+oLRlEVY9XBvZBI7il/HyUrb2nJ505wE1MHEFyDZNnrWDEuy4jL50WVHfTTSQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-string-parser": "^7.29.11", + "@babel/helper-validator-identifier": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.12.tgz", + "integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.12.tgz", + "integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.12.tgz", + "integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.12.tgz", + "integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.12.tgz", + "integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.12.tgz", + "integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.12.tgz", + "integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.12.tgz", + "integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.12.tgz", + "integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.12.tgz", + "integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.12.tgz", + "integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.12.tgz", + "integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.12.tgz", + "integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.12.tgz", + "integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.12.tgz", + "integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.12.tgz", + "integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.12.tgz", + "integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.12.tgz", + "integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.12.tgz", + "integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.12.tgz", + "integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.12.tgz", + "integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.12.tgz", + "integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.12.tgz", + "integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.12.tgz", + "integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.12.tgz", + "integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.12.tgz", + "integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", + "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0", + "@jridgewell/trace-mapping": "^0.3.24" + } + }, + "node_modules/@jridgewell/remapping": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", + "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.24" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.0-beta.27", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz", + "integrity": "sha512-+d0F4MKMCbeVUJwG96uQ4SgAznZNSq93I3V+9NHA4OpvqG8mRCpGdKmK8l/dl02h2CCDHwW2FqilnTyDcAnqjA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.68.0.tgz", + "integrity": "sha512-Ta2n0ntLfzP0LqwwcXOIh2z0mnHjlxMS+h4Y9lo+w33Quyf9KFKEi9QZ2IKqeEBKr0qxNpXc/DQjz5KVIs8AEA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.68.0.tgz", + "integrity": "sha512-iFDtS0oMaBvKbtrRKXmRcBSsI0UaWL2bWpd62iHzb0A8RSPrVz47mUGE0CfrrD0c/7/7dUhNtoN3cc6aEUn1Ow==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-x64": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-x64/-/rollup-android-x64-4.68.0.tgz", + "integrity": "sha512-OnYETr+cZYSbesBD1tCvUjrBUTkjSaOcewRUoIHqD0XI3yn5i9WpdFaE3LZwrMlq0yeJNU0N5sxfHK/fNVMqlQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.68.0.tgz", + "integrity": "sha512-2qavWZtFeon/6oMkjsBF3OH7ENKgRTW4xRTwmz9VJeNUYhmPitpR9Jd4sAAc2OZJryHs2neoovMTCYnNvhvANQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.68.0.tgz", + "integrity": "sha512-QpgJO+GwNQDPt6uYcFSjZTFVyHNIeumN2am7RISDR9Nf3e/h8sur9cIfplPGihZPUn+sTw9j3JErZIUkHg8+Pw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.68.0.tgz", + "integrity": "sha512-TERqEn6P9bp4lsTyoFjT3nLKV6G++76HhGb4k6dRGcs+jvhVcTGaS2zkeRdLLRjwKxpBtdCZe11kUQ2hNGgFSA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.68.0.tgz", + "integrity": "sha512-RBjDrqb7h5l6Xgdgz5eKYvbpnUkii/z5ejWuZmHJsXORi0X0tTtFzEEgJj2DX995kW18c6T9LGFn/deEAMXDcQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.68.0.tgz", + "integrity": "sha512-HtLgXBqjF1Ampt9eJjzSmoGDvNb4LP8Y2aPXQZeQ5qhyExXLmoXJB9Jfm/nPi/8fJ3UFn4sZ7pQKyr8V+oTN8g==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.68.0.tgz", + "integrity": "sha512-q51xJyqjaqCNtDjYD7xNVwsPa2TcVfAIBeP6E20wicKZ6XYp8Taz9SUPYhIENojAQIAoV7cO3mUdMUgWYEAuhQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.68.0.tgz", + "integrity": "sha512-wejnVabl92oFC/o4sr/EEJuJZMHtMq4C+LBIPphN4EUiVHe9qvZNw+biqhVHpX2ggs1+Z3ugXGwJxT+qhyaaYQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.68.0.tgz", + "integrity": "sha512-tyu+hrsCWHHqV6+2tligV/recJH+HVvNV2Sp4nS1C+MKQPkNXRovKIzyHy0V0xXjm6igCLgsT2vTky5CvWP37g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-gnu": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.68.0.tgz", + "integrity": "sha512-5gjJNglKDfgs3OmnGi/RVZQPhEfRoCIHxwSAP9ngmdnxreu0Vl9lI4gxmFBXOhKdftpS82xRdc/7Dp5/A1F0qg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-musl": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.68.0.tgz", + "integrity": "sha512-2IBxTUds33rFYwOIEyf77wfW8WQThwiQQ1ofXSraZQG7PiIq7BnQBf/ge0qEI/Ny/2cSc7SKkGO/wUDqmYXqTg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-gnu": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.68.0.tgz", + "integrity": "sha512-mE/Pj2PPTZIVHkNNuHq+eYoU3td8LCm73zjrXoBWkNlnuULJS2l/fxwgGPpN4WUCNZgKZ1IXwrnnETPyOcWPmg==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-musl": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.68.0.tgz", + "integrity": "sha512-dYuykUkAiTv+RQdP3Ib47XcFiImkBWiRpTGSQWAMfZPQyoQYGe8Je4IUeZYNUQWIojmRCUnt5xsH4BbUb2uqSw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.68.0.tgz", + "integrity": "sha512-OnPDDFXLqJewY56T6ow8sA4wuzbqlliD7QJgkrx2KX+pWOpjI3usYXgB0pwK3nsgTF2odCw9IuJs0Uis/jy2qA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-musl": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.68.0.tgz", + "integrity": "sha512-CqoQf06cK0brrRfDqH7Mt8G4MdteFGbjBdC61zEMaSVna6xo6QMUixa9bAkAD4a92g3ElPbQAkLMUzdf+Lk8dg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.68.0.tgz", + "integrity": "sha512-LPHNmE8GwiyELGLUTkqj4zsP1YEHzGdtwnKxAcdP/swsNxXsfxPtpe5nrD/KGxr136xPB+eWv2r/SGj9md0pnQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.68.0.tgz", + "integrity": "sha512-GDOmvgephpRCNyNGRQOZh0KD2gTyRVM1Bb1iOo759xeCUpCAoRCmJioOOSu2MwyWfNOocGd0V5I9vYLfteC6/A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.68.0.tgz", + "integrity": "sha512-HADRxkvl5eg3hbemCmv81UwTfdQy/CiSJDOabLE+p5tpm3OTjuRtzpLXy5zPfGY9FQD4Qv7qHptXmG/YjmNmyw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-openbsd-x64": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.68.0.tgz", + "integrity": "sha512-iERrpqu1VEfyX736HLKiXRbwGDkCV/iybARY/mn14KcI6oKhJGBx1e+bU+g+umTKghtiGSPaHkwwpII4/N3RjA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/@rollup/rollup-openharmony-arm64": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.68.0.tgz", + "integrity": "sha512-hBn57IqAbpXpyktckonwePTaFOQS6THph8ZnpRO3eZHY4LncuZGjSsseigBnKuSMKKpLnJJ7PemDvXEzniXC+A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.68.0.tgz", + "integrity": "sha512-pJWb7mIw9Z25Hl3Q6nHFjl7AnczfOpm2gbOFYguSRv6TiH7DzsoAk/thymb/URSQu9OUEK7uaDMC5Xfm+7TAww==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.68.0.tgz", + "integrity": "sha512-pnrhmoyF2otH2Mezol14/ELUFGuRddOCz6+I+J0pq2Itnp4UxkjABQcXawCNMaKNsCRiuL90BtNzbEd0fHjpIg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-gnu": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.68.0.tgz", + "integrity": "sha512-1dJ3U+ktdtaIdPaOZKwIX57+bKQk4iAjs5M1wQWLKRB6Wglp98qf8LUeuN4u6bGlIYouZKaySZJ5Qd4OalUMnA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.68.0.tgz", + "integrity": "sha512-e/NRJFl48wL5DFNSzQrvm4kaB5dzNNmqWjIJ6And2Sjuw4klO3w3TXMvCAEF1tHTrQQgpOD4QVkBE/92/yBGrQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@types/babel__core": { + "version": "7.20.5", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", + "integrity": "sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.20.7", + "@babel/types": "^7.20.7", + "@types/babel__generator": "*", + "@types/babel__template": "*", + "@types/babel__traverse": "*" + } + }, + "node_modules/@types/babel__generator": { + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.27.0.tgz", + "integrity": "sha512-ufFd2Xi92OAVPYsy+P4n7/U7e68fex0+Ee8gSG9KX7eo084CWiQ4sdxktvdl0bOPupXtVJPY19zk6EwWqUQ8lg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.0.0" + } + }, + "node_modules/@types/babel__template": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.4.tgz", + "integrity": "sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.1.0", + "@babel/types": "^7.0.0" + } + }, + "node_modules/@types/babel__traverse": { + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.28.0.tgz", + "integrity": "sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.28.2" + } + }, + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/prop-types": { + "version": "15.7.15", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", + "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/react": { + "version": "18.3.31", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.31.tgz", + "integrity": "sha512-vfEqpXTvwT91yhmwdfouStN2hSKwTvyRs8qpLfADyrq/kxDw0hZM7Wk9Ug1FELj8hIby+S/+kQCSRFF32nv2Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/prop-types": "*", + "csstype": "^3.2.2" + } + }, + "node_modules/@types/react-dom": { + "version": "18.3.7", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.7.tgz", + "integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@types/react": "^18.0.0" + } + }, + "node_modules/@vitejs/plugin-react": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.7.0.tgz", + "integrity": "sha512-gUu9hwfWvvEDBBmgtAowQCojwZmJ5mcLn3aufeCsitijs3+f2NsrPtlAWIR6OPiqljl96GVCUbLe0HyqIpVaoA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/core": "^7.28.0", + "@babel/plugin-transform-react-jsx-self": "^7.27.1", + "@babel/plugin-transform-react-jsx-source": "^7.27.1", + "@rolldown/pluginutils": "1.0.0-beta.27", + "@types/babel__core": "^7.20.5", + "react-refresh": "^0.17.0" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "peerDependencies": { + "vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0" + } + }, + "node_modules/baseline-browser-mapping": { + "version": "2.11.35", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.35.tgz", + "integrity": "sha512-GNk8KX52CHqeNKGk8+7tZnQab/2k1t/BgrUHPKNdijzpEhF1saPQZHVKb6m5loSAxB39gyrTYw34Qf9CQ3u1qQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "baseline-browser-mapping": "dist/cli.cjs" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/browserslist": { + "version": "4.29.5", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.29.5.tgz", + "integrity": "sha512-khTmKu5NGYTotqcYo8Bew2k4RAE9PuXRSFRXG2lQBrCEQHyeQ/vX6gKMxfokwywBsLiXZMnHsmWMG1pnO8J7uQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "baseline-browser-mapping": "^2.11.33", + "caniuse-lite": "^1.0.30001819", + "electron-to-chromium": "^1.5.464", + "node-releases": "^2.0.60", + "update-browserslist-db": "^1.3.4" + }, + "bin": { + "browserslist": "cli.js" + }, + "engines": { + "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" + } + }, + "node_modules/caniuse-lite": { + "version": "1.0.30001823", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001823.tgz", + "integrity": "sha512-TQ5s/djDjNk1axreUW+4rULH+BmdCMLiJkhaXnO5wqivG7tITkSUj4ItIdzqdZHKaXcHAV8dhH3JxOM7/7bwqw==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "CC-BY-4.0" + }, + "node_modules/convert-source-map": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "dev": true, + "license": "MIT" + }, + "node_modules/csstype": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", + "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/electron-to-chromium": { + "version": "1.5.478", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.478.tgz", + "integrity": "sha512-pftG+ma5Lm8O6/p45bhYT6StBN5ziQymaRzmCZwFl8DwWHKPPD93FdOmP1aqftcepolQYvrcyTLa17kE8Yf+jg==", + "dev": true, + "license": "ISC" + }, + "node_modules/esbuild": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz", + "integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.12", + "@esbuild/android-arm": "0.25.12", + "@esbuild/android-arm64": "0.25.12", + "@esbuild/android-x64": "0.25.12", + "@esbuild/darwin-arm64": "0.25.12", + "@esbuild/darwin-x64": "0.25.12", + "@esbuild/freebsd-arm64": "0.25.12", + "@esbuild/freebsd-x64": "0.25.12", + "@esbuild/linux-arm": "0.25.12", + "@esbuild/linux-arm64": "0.25.12", + "@esbuild/linux-ia32": "0.25.12", + "@esbuild/linux-loong64": "0.25.12", + "@esbuild/linux-mips64el": "0.25.12", + "@esbuild/linux-ppc64": "0.25.12", + "@esbuild/linux-riscv64": "0.25.12", + "@esbuild/linux-s390x": "0.25.12", + "@esbuild/linux-x64": "0.25.12", + "@esbuild/netbsd-arm64": "0.25.12", + "@esbuild/netbsd-x64": "0.25.12", + "@esbuild/openbsd-arm64": "0.25.12", + "@esbuild/openbsd-x64": "0.25.12", + "@esbuild/openharmony-arm64": "0.25.12", + "@esbuild/sunos-x64": "0.25.12", + "@esbuild/win32-arm64": "0.25.12", + "@esbuild/win32-ia32": "0.25.12", + "@esbuild/win32-x64": "0.25.12" + } + }, + "node_modules/escalade": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/gensync": { + "version": "1.0.0-beta.2", + "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", + "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "license": "MIT" + }, + "node_modules/jsesc": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", + "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", + "dev": true, + "license": "MIT", + "bin": { + "jsesc": "bin/jsesc" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "license": "MIT", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "license": "MIT", + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, + "node_modules/lru-cache": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", + "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", + "dev": true, + "license": "ISC", + "dependencies": { + "yallist": "^3.0.2" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/node-releases": { + "version": "2.0.63", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.63.tgz", + "integrity": "sha512-6li2QanLsAXpIH2R6j77MzRyvOyrvdTqlKtO4CgBdHGNvN99ZZfyxszHc5o5+IZBWD5u6Hzwg83JoGXmqZNG9Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.32", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz", + "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "license": "MIT", + "dependencies": { + "loose-envify": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", + "license": "MIT", + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.2" + }, + "peerDependencies": { + "react": "^18.3.1" + } + }, + "node_modules/react-refresh": { + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz", + "integrity": "sha512-z6F7K9bV85EfseRCp2bzrpyQ0Gkw1uLoCel9XBVWPg/TjRj94SkJzUTGfOa4bs7iJvBWtQG0Wq7wnI0syw3EBQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/rollup": { + "version": "4.68.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.68.0.tgz", + "integrity": "sha512-BIHWnc1Qjdy+WLfOdcSd67sxO4iW6pTnhdZosg+7ywSaiMWxxzKldkkNpUJqeXYAiJzyB14P2cIjqC6tlb6xzw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.10" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.68.0", + "@rollup/rollup-android-arm64": "4.68.0", + "@rollup/rollup-android-x64": "4.68.0", + "@rollup/rollup-darwin-arm64": "4.68.0", + "@rollup/rollup-darwin-x64": "4.68.0", + "@rollup/rollup-freebsd-arm64": "4.68.0", + "@rollup/rollup-freebsd-x64": "4.68.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.68.0", + "@rollup/rollup-linux-arm-musleabihf": "4.68.0", + "@rollup/rollup-linux-arm64-gnu": "4.68.0", + "@rollup/rollup-linux-arm64-musl": "4.68.0", + "@rollup/rollup-linux-loong64-gnu": "4.68.0", + "@rollup/rollup-linux-loong64-musl": "4.68.0", + "@rollup/rollup-linux-ppc64-gnu": "4.68.0", + "@rollup/rollup-linux-ppc64-musl": "4.68.0", + "@rollup/rollup-linux-riscv64-gnu": "4.68.0", + "@rollup/rollup-linux-riscv64-musl": "4.68.0", + "@rollup/rollup-linux-s390x-gnu": "4.68.0", + "@rollup/rollup-linux-x64-gnu": "4.68.0", + "@rollup/rollup-linux-x64-musl": "4.68.0", + "@rollup/rollup-openbsd-x64": "4.68.0", + "@rollup/rollup-openharmony-arm64": "4.68.0", + "@rollup/rollup-win32-arm64-msvc": "4.68.0", + "@rollup/rollup-win32-ia32-msvc": "4.68.0", + "@rollup/rollup-win32-x64-gnu": "4.68.0", + "@rollup/rollup-win32-x64-msvc": "4.68.0", + "fsevents": "~2.3.2" + } + }, + "node_modules/scheduler": { + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", + "license": "MIT", + "dependencies": { + "loose-envify": "^1.1.0" + } + }, + "node_modules/semver": { + "version": "6.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.2.tgz", + "integrity": "sha512-GYrCADwpu6yV5OAvchkQ27Z5wwMxWAEMg5NNWjyHh/5DboFFqbdbvYNIvZouQpxXyeMPoTOh0vdPYKlf0ZswdQ==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/source-map-js": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", + "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/update-browserslist-db": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.3.4.tgz", + "integrity": "sha512-t8wonIOdQyOjtPd2VktlBu6QjTVTks6v8bSi7kd0r2Vll8TK1JYDZtRRdbmCHOAMphkZgrzK+L+vXK4pyZ8t4A==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "escalade": "^3.2.0", + "picocolors": "^1.1.1" + }, + "bin": { + "update-browserslist-db": "cli.js" + }, + "peerDependencies": { + "browserslist": ">= 4.21.0" + } + }, + "node_modules/vite": { + "version": "6.4.5", + "resolved": "https://registry.npmjs.org/vite/-/vite-6.4.5.tgz", + "integrity": "sha512-4enwjFfi4IwtEh0w+jPzpLVOFQiPHmmzPxcHXQOyEur47o6u0jE573DmGpjA+7irXoMLYRZD5ZaFUEneS3abPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "^0.25.0", + "fdir": "^6.4.4", + "picomatch": "^4.0.2", + "postcss": "^8.5.3", + "rollup": "^4.34.9", + "tinyglobby": "^0.2.13" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", + "jiti": ">=1.21.0", + "less": "*", + "lightningcss": "^1.21.0", + "sass": "*", + "sass-embedded": "*", + "stylus": "*", + "sugarss": "*", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/yallist": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", + "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", + "dev": true, + "license": "ISC" + } + } +} diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000000000000000000000000000000000000..877ca3d798d591b254e63bcef8bd52b6522ee949 --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,23 @@ +{ + "name": "empathvoice-frontend", + "private": true, + "version": "0.2.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc -b && vite build", + "preview": "vite preview", + "lint": "tsc --noEmit" + }, + "dependencies": { + "react": "^18.3.1", + "react-dom": "^18.3.1" + }, + "devDependencies": { + "@types/react": "^18.3.12", + "@types/react-dom": "^18.3.1", + "@vitejs/plugin-react": "^4.3.4", + "typescript": "^5.6.3", + "vite": "^6.0.7" + } +} diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx new file mode 100644 index 0000000000000000000000000000000000000000..ecb8d1fb7f6a5c2dbf9e875d8e387376253b3567 --- /dev/null +++ b/frontend/src/App.tsx @@ -0,0 +1,168 @@ +import { useCallback, useEffect, useRef, useState } from "react"; +import { api, ApiRequestError } from "./api"; +import { MAX_CHARS } from "./constants"; +import { useDebounced } from "./hooks"; +import type { AnalyzeResponse, Voice } from "./types"; +import { TextComposer } from "./components/TextComposer"; +import { VoicePicker } from "./components/VoicePicker"; +import { AnalysisPanel } from "./components/AnalysisPanel"; +import { AudioPlayer } from "./components/AudioPlayer"; +import { Banner } from "./components/Banner"; + +type ModelState = "loading" | "ready" | "failed"; + +async function fetchReady(): Promise { + try { + const r = await fetch("/ready"); + const j = await r.json(); + return (j.model_status as ModelState) ?? "loading"; + } catch { + return "loading"; + } +} + +export default function App() { + const [text, setText] = useState(""); + const [voices, setVoices] = useState([]); + const [voice, setVoice] = useState(""); + const [modelState, setModelState] = useState("loading"); + + const [analysis, setAnalysis] = useState(null); + const [analyzing, setAnalyzing] = useState(false); + const [generating, setGenerating] = useState(false); + const [audio, setAudio] = useState<{ url: string; expiresIn: number } | null>(null); + const [error, setError] = useState(null); + + const debouncedText = useDebounced(text.trim(), 500); + const analyzeSeq = useRef(0); // guards against out-of-order responses + + const ready = modelState === "ready"; + const trimmed = text.trim(); + const valid = trimmed.length > 0 && trimmed.length <= MAX_CHARS; + + // --- Load voices + poll readiness on mount --- + useEffect(() => { + api + .getVoices() + .then((v) => { + setVoices(v.voices); + setVoice(v.default); + }) + .catch(() => setError("Could not load voices.")); + + let active = true; + const poll = async () => { + const s = await fetchReady(); + if (!active) return; + setModelState(s); + if (s === "loading") setTimeout(poll, 2000); + }; + poll(); + return () => { + active = false; + }; + }, []); + + // --- Debounced live analysis preview --- + useEffect(() => { + if (!ready || !debouncedText || debouncedText.length > MAX_CHARS) { + if (!debouncedText) setAnalysis(null); + return; + } + const seq = ++analyzeSeq.current; + setAnalyzing(true); + api + .analyze(debouncedText) + .then((res) => { + if (seq === analyzeSeq.current) setAnalysis(res); + }) + .catch((e: ApiRequestError) => { + if (seq === analyzeSeq.current) setError(e.message); + }) + .finally(() => { + if (seq === analyzeSeq.current) setAnalyzing(false); + }); + }, [debouncedText, ready]); + + // --- Generate speech --- + const generate = useCallback(async () => { + if (!valid || !ready) return; + setGenerating(true); + setError(null); + try { + const res = await api.synthesize(trimmed, voice); + setAnalysis(res.analysis); + setAudio({ url: res.audio_url, expiresIn: res.expires_in_seconds }); + } catch (e) { + const err = e as ApiRequestError; + setError(err.message); + } finally { + setGenerating(false); + } + }, [valid, ready, trimmed, voice]); + + const busy = analyzing || generating; + + return ( +
+
+
+
+ + + + + + +
+
+

EmpathVoice

+

Emotion-aware text to speech

+
+
+ + {modelState === "loading" && ( + + )} + {modelState === "failed" && ( + + )} + {error && setError(null)} />} + + + +
+ + +
+ + {/* States: empty / analyzing / analysis preview / audio */} + {!trimmed && !analysis && ( +

+ Enter some text to see its estimated emotional delivery, then generate speech. +

+ )} + + {analyzing && !analysis &&

Analyzing…

} + + {analysis && } + + {audio && } +
+ +
+ Emotion and VAD values are model estimates, not definitive readings of feeling. +
+
+ ); +} diff --git a/frontend/src/api.ts b/frontend/src/api.ts new file mode 100644 index 0000000000000000000000000000000000000000..c50ee2ddc7be09efe04f617e7c1404c86d754e3a --- /dev/null +++ b/frontend/src/api.ts @@ -0,0 +1,59 @@ +import type { + AnalyzeResponse, + SynthesizeResponse, + VoicesResponse, +} from "./types"; + +/** Thrown for any non-2xx response, carrying the backend error code/message. */ +export class ApiRequestError extends Error { + code: string; + status: number; + constructor(status: number, code: string, message: string) { + super(message); + this.code = code; + this.status = status; + } +} + +async function request(path: string, body?: unknown): Promise { + let res: Response; + try { + res = await fetch(path, { + method: body === undefined ? "GET" : "POST", + headers: body === undefined ? undefined : { "Content-Type": "application/json" }, + body: body === undefined ? undefined : JSON.stringify(body), + }); + } catch { + throw new ApiRequestError(0, "network_error", "Could not reach the server."); + } + + if (!res.ok) { + let code = "error"; + let message = `Request failed (${res.status}).`; + try { + const data = await res.json(); + if (data?.error) { + code = data.error.code ?? code; + message = data.error.message ?? message; + } else if (data?.detail) { + // FastAPI validation errors (422) use `detail`. + code = "validation_error"; + message = Array.isArray(data.detail) + ? data.detail[0]?.msg ?? message + : String(data.detail); + } + } catch { + /* non-JSON body; keep defaults */ + } + throw new ApiRequestError(res.status, code, message); + } + + return (await res.json()) as T; +} + +export const api = { + getVoices: () => request("/api/voices"), + analyze: (text: string) => request("/api/analyze", { text }), + synthesize: (text: string, voice: string) => + request("/api/synthesize", { text, voice }), +}; diff --git a/frontend/src/components/AnalysisPanel.tsx b/frontend/src/components/AnalysisPanel.tsx new file mode 100644 index 0000000000000000000000000000000000000000..572b429edeb2025cf6bc28e8abb80979b74e9ec0 --- /dev/null +++ b/frontend/src/components/AnalysisPanel.tsx @@ -0,0 +1,66 @@ +import type { AnalyzeResponse } from "../types"; +import { ENERGY_PCT_MAX, PITCH_HZ_MAX, RATE_PCT_MAX } from "../constants"; +import { Meter } from "./Meter"; + +interface Props { + analysis: AnalyzeResponse; + stale?: boolean; // dimmed while a newer analysis is loading +} + +const signed = (v: number, unit: string) => `${v >= 0 ? "+" : ""}${v}${unit}`; + +export function AnalysisPanel({ analysis, stale }: Props) { + const { top_emotions, vad, prosody, explanation } = analysis; + + return ( +
+

{explanation}

+ +
+
+

Estimated tone

+ {top_emotions.map((e) => ( + + ))} +
+ +
+

Affect (VAD)

+ + + +
+ +
+

Delivery

+ = 0} + /> + = 0} + /> + = 0} + /> + +
+
+
+ ); +} diff --git a/frontend/src/components/AudioPlayer.tsx b/frontend/src/components/AudioPlayer.tsx new file mode 100644 index 0000000000000000000000000000000000000000..5d258948422f4d1dc8ed8757a310cbe5f8b2c963 --- /dev/null +++ b/frontend/src/components/AudioPlayer.tsx @@ -0,0 +1,22 @@ +interface Props { + url: string; + expiresIn: number; +} + +export function AudioPlayer({ url, expiresIn }: Props) { + const minutes = Math.round(expiresIn / 60); + return ( +
+ {/* key=url forces the element to reload when a new clip is generated */} + +
+ + Download MP3 + + Link expires in ~{minutes} min +
+
+ ); +} diff --git a/frontend/src/components/Banner.tsx b/frontend/src/components/Banner.tsx new file mode 100644 index 0000000000000000000000000000000000000000..fdb507a570a112c3ead405f1ee9701160568089b --- /dev/null +++ b/frontend/src/components/Banner.tsx @@ -0,0 +1,18 @@ +interface Props { + kind: "error" | "info"; + message: string; + onDismiss?: () => void; +} + +export function Banner({ kind, message, onDismiss }: Props) { + return ( +
+ {message} + {onDismiss && ( + + )} +
+ ); +} diff --git a/frontend/src/components/Meter.tsx b/frontend/src/components/Meter.tsx new file mode 100644 index 0000000000000000000000000000000000000000..85e376ce23b75c8f47ec572490a502a33a2df5ab --- /dev/null +++ b/frontend/src/components/Meter.tsx @@ -0,0 +1,37 @@ +interface MeterProps { + label: string; + /** 0..1 fill fraction. */ + fraction: number; + /** Text shown on the right (e.g. "0.82" or "+12 Hz"). */ + value: string; + /** Signed meters fill from the centre; unsigned fill from the left. */ + signed?: boolean; + /** Sign for colouring a signed meter. */ + positive?: boolean; +} + +export function Meter({ label, fraction, value, signed = false, positive = true }: MeterProps) { + const pct = Math.round(Math.min(1, Math.max(0, fraction)) * 100); + const toneClass = signed ? (positive ? "meter-pos" : "meter-neg") : "meter-neutral"; + + return ( +
+
+ {label} + {value} +
+
+ {signed && } + +
+
+ ); +} diff --git a/frontend/src/components/TextComposer.tsx b/frontend/src/components/TextComposer.tsx new file mode 100644 index 0000000000000000000000000000000000000000..2ba43ba169a6b77557b6452fe16e063fe7006369 --- /dev/null +++ b/frontend/src/components/TextComposer.tsx @@ -0,0 +1,47 @@ +import { EXAMPLES, MAX_CHARS } from "../constants"; + +interface Props { + value: string; + onChange: (text: string) => void; + disabled?: boolean; +} + +export function TextComposer({ value, onChange, disabled }: Props) { + const over = value.length > MAX_CHARS; + + return ( +
+
+ +