Arabi32 commited on
Commit
2dbc437
ยท
verified ยท
1 Parent(s): bd63eef

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile (1) +41 -0
  2. README (9).md +31 -0
  3. app (5).py +312 -0
  4. requirements (6).txt +11 -0
Dockerfile (1) ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # โ”€โ”€ Base image โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
2
+ FROM python:3.10-slim
3
+
4
+ # โ”€โ”€ System deps (audio libs required by TTS / soundfile) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
5
+ RUN apt-get update && apt-get install -y --no-install-recommends \
6
+ build-essential \
7
+ libsndfile1 \
8
+ ffmpeg \
9
+ git \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # โ”€โ”€ HuggingFace Spaces: non-root user uid=1000 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
13
+ RUN useradd -m -u 1000 user
14
+ USER user
15
+
16
+ ENV HOME=/home/user \
17
+ PATH=/home/user/.local/bin:$PATH \
18
+ # Accept Coqui TOS automatically
19
+ COQUI_TOS_AGREED=1 \
20
+ # Keep HF model cache inside the container's writable home
21
+ HF_HOME=/home/user/.cache/huggingface \
22
+ # Avoid tokeniser parallelism warnings
23
+ TOKENIZERS_PARALLELISM=false
24
+
25
+ WORKDIR $HOME/app
26
+
27
+ # โ”€โ”€ Python deps โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
28
+ COPY --chown=user requirements.txt .
29
+ RUN pip install --no-cache-dir --upgrade pip \
30
+ && pip install --no-cache-dir -r requirements.txt
31
+
32
+ # โ”€โ”€ App code โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
33
+ COPY --chown=user app.py .
34
+
35
+ # โ”€โ”€ Runtime dirs (writable by user 1000) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
36
+ RUN mkdir -p /home/user/app/voice_library /home/user/app/outputs
37
+
38
+ # โ”€โ”€ HuggingFace Spaces listens on 7860 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
39
+ EXPOSE 7860
40
+
41
+ CMD ["python", "app.py"]
README (9).md ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: XTTS Voice Studio
3
+ emoji: ๐ŸŽ™๏ธ
4
+ colorFrom: yellow
5
+ colorTo: orange
6
+ sdk: docker
7
+ app_port: 7860
8
+ pinned: false
9
+ ---
10
+
11
+ # XTTS v2 Voice Studio
12
+
13
+ A multilingual text-to-speech studio powered by **Coqui XTTS v2**, served via **FastAPI** (no Gradio).
14
+
15
+ ## Features
16
+ - 16 supported languages (Arabic, English, French, โ€ฆ)
17
+ - Voice cloning from uploaded audio samples
18
+ - Persistent voice library
19
+ - Generation history with playback & download
20
+ - Fully custom React UI
21
+
22
+ ## Usage
23
+ 1. Upload a reference audio clip (WAV / MP3 / FLAC, โ‰ฅ 6 s recommended).
24
+ 2. Type your text and pick a language.
25
+ 3. Adjust advanced parameters if needed.
26
+ 4. Click **โšก ุชูˆู„ูŠุฏ ุงู„ุตูˆุช** and wait โ€” CPU inference takes ~30โ€“90 s per request.
27
+
28
+ ## Notes
29
+ - Running on **CPU**; generation is slower than GPU but fully functional.
30
+ - The XTTS v2 model (~1.8 GB) is downloaded on first startup and cached.
31
+ - `COQUI_TOS_AGREED=1` is set automatically โ€” by using this Space you agree to the [Coqui TTS terms](https://coqui.ai/cpml).
app (5).py ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
2
+ # โ•‘ XTTS v2 Advanced Voice Studio โ€” HuggingFace Space โ•‘
3
+ # โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
4
+
5
+ import os, sys, time, json, uuid, shutil, threading
6
+
7
+ import uvicorn
8
+ from fastapi import FastAPI, Form, File, UploadFile, HTTPException
9
+ from fastapi.responses import HTMLResponse, FileResponse, JSONResponse
10
+ from fastapi.middleware.cors import CORSMiddleware
11
+ import torch
12
+
13
+ # โ”€โ”€ Env โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14
+ os.environ["COQUI_TOS_AGREED"] = "1"
15
+ # Point HF cache to a writable directory inside the Space
16
+ os.environ.setdefault("HF_HOME", "/home/user/.cache/huggingface")
17
+
18
+ VOICE_LIB = "/home/user/app/voice_library"
19
+ OUTPUT_DIR = "/home/user/app/outputs"
20
+ HISTORY_FILE = "/home/user/app/history.json"
21
+
22
+ for d in [VOICE_LIB, OUTPUT_DIR]:
23
+ os.makedirs(d, exist_ok=True)
24
+
25
+ # โ”€โ”€ Load TTS on CPU โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
26
+ from TTS.api import TTS
27
+
28
+ # HF Spaces free tier is CPU-only; force CPU explicitly
29
+ device = "cpu"
30
+
31
+ print(f"[*] Loading XTTS v2 on {device.upper()} โ€ฆ")
32
+ xtts_engine = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
33
+ print("[โœ“] Model ready.")
34
+
35
+ # โ”€โ”€ History helpers โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
36
+ def load_history():
37
+ if os.path.exists(HISTORY_FILE):
38
+ try:
39
+ return json.load(open(HISTORY_FILE))
40
+ except Exception:
41
+ pass
42
+ return []
43
+
44
+ def save_history(h):
45
+ json.dump(h, open(HISTORY_FILE, "w"), ensure_ascii=False, indent=2)
46
+
47
+ # โ”€โ”€ FastAPI app โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
48
+ app = FastAPI(title="XTTS Studio")
49
+ app.add_middleware(
50
+ CORSMiddleware,
51
+ allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]
52
+ )
53
+
54
+ LANGUAGES = {
55
+ "ar": "ุงู„ุนุฑุจูŠุฉ", "en": "English", "es": "Espaรฑol", "fr": "Franรงais",
56
+ "de": "Deutsch", "it": "Italiano", "pt": "Portuguรชs","ru": "ะ ัƒััะบะธะน",
57
+ "zh-cn": "ไธญๆ–‡", "ja": "ๆ—ฅๆœฌ่ชž", "ko": "ํ•œ๊ตญ์–ด", "tr": "Tรผrkรงe",
58
+ "nl": "Nederlands","pl": "Polski", "cs": "ฤŒeลกtina", "hi": "เคนเคฟเคจเฅเคฆเฅ€",
59
+ }
60
+
61
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
62
+ # HTML / React Frontend
63
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
64
+ HTML = r"""<!DOCTYPE html>
65
+ <html lang="ar" dir="rtl">
66
+ <head>
67
+ <meta charset="UTF-8">
68
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
69
+ <title>XTTS Voice Studio</title>
70
+ <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=IBM+Plex+Sans+Arabic:wght@300;400;600;700&display=swap" rel="stylesheet">
71
+ <script src="https://cdn.tailwindcss.com"></script>
72
+ <script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
73
+ <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
74
+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
75
+ <style>
76
+ :root { --bg: #0b0c0f; --surface: #13151a; --border: #1f2330; --amber: #f5a623; --amber-dim:#a06a10; --green: #3ddc84; --red: #ff5252; --text: #e8eaf0; --muted: #6b7280; --mono: 'IBM Plex Mono', monospace; --sans: 'IBM Plex Sans Arabic', sans-serif; }
77
+ * { box-sizing: border-box; } body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); min-height: 100vh; }
78
+ ::-webkit-scrollbar { width: 5px; } ::-webkit-scrollbar-track { background: var(--surface); } ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
79
+ body::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; background: repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(255,255,255,.02) 40px); }
80
+ .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; } .amber { color: var(--amber); } .tag { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
81
+ input[type=range] { -webkit-appearance: none; width: 100%; height: 3px; background: var(--border); border-radius: 2px; outline: none; } input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; background: var(--amber); border-radius: 50%; cursor: pointer; transition: transform .15s; } input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.3); }
82
+ select, textarea { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px 10px; font-family: var(--sans); outline: none; transition: border-color .2s; } textarea { resize: vertical; padding: 12px; width: 100%; } select:focus, textarea:focus { border-color: var(--amber); }
83
+ .file-drop { border: 2px dashed var(--border); border-radius: 8px; padding: 16px; text-align: center; cursor: pointer; transition: border-color .2s, background .2s; position: relative; } .file-drop:hover, .file-drop.active { border-color: var(--amber); background: rgba(245,166,35,.05); } .file-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
84
+ .btn-primary { background: var(--amber); color: #000; font-weight: 700; border: none; border-radius: 8px; padding: 14px 24px; cursor: pointer; font-family: var(--sans); font-size: 15px; width: 100%; transition: opacity .2s, transform .1s; } .btn-primary:hover { opacity: .9; } .btn-primary:active { transform: scale(.98); } .btn-primary:disabled { opacity: .4; cursor: not-allowed; }
85
+ .btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 12px; transition: color .2s, border-color .2s; } .btn-ghost:hover { color: var(--text); border-color: var(--muted); }
86
+ .badge { display: inline-flex; align-items: center; gap: 4px; background: rgba(245,166,35,.12); border: 1px solid rgba(245,166,35,.3); color: var(--amber); border-radius: 20px; padding: 2px 10px; font-size: 11px; font-family: var(--mono); } .badge.green { background: rgba(61,220,132,.1); border-color: rgba(61,220,132,.3); color: var(--green); } .badge.red { background: rgba(255,82,82,.1); border-color: rgba(255,82,82,.3); color: var(--red); }
87
+ .waveform { display: flex; align-items: center; gap: 3px; height: 28px; } .waveform span { flex: 1; background: var(--amber); border-radius: 2px; animation: wave 1s ease-in-out infinite; opacity: .7; } @keyframes wave { 0%,100%{height:4px} 50%{height:24px} } .waveform span:nth-child(2){animation-delay:.1s} .waveform span:nth-child(3){animation-delay:.2s} .waveform span:nth-child(4){animation-delay:.3s} .waveform span:nth-child(5){animation-delay:.2s} .waveform span:nth-child(6){animation-delay:.1s} .waveform span:nth-child(7){animation-delay:.05s}
88
+ .tab { cursor:pointer; padding:8px 16px; border-radius:6px; font-size:13px; color:var(--muted); transition:all .2s; } .tab.active { background:rgba(245,166,35,.15); color:var(--amber); } .tab:hover:not(.active) { color:var(--text); }
89
+ audio { width:100%; accent-color:var(--amber); } audio::-webkit-media-controls-panel { background:var(--surface); }
90
+ .history-row { display:flex; align-items:center; gap:12px; padding:10px 14px; border-radius:8px; border:1px solid var(--border); background:var(--bg); transition:border-color .2s; } .history-row:hover { border-color: var(--amber-dim); }
91
+ .param-row { display:grid; grid-template-columns:140px 1fr 48px; align-items:center; gap:12px; } .param-label { font-size:12px; color:var(--muted); font-family:var(--mono); } .param-val { font-size:13px; color:var(--amber); font-family:var(--mono); text-align:right; }
92
+ .voice-card { padding:10px 14px; border-radius:8px; border:1px solid var(--border); background:var(--bg); cursor:pointer; transition:all .2s; display:flex; align-items:center; justify-content:space-between; } .voice-card:hover { border-color:var(--amber-dim); } .voice-card.selected { border-color:var(--amber); background:rgba(245,166,35,.06); }
93
+ </style>
94
+ </head>
95
+ <body>
96
+ <div id="root"></div>
97
+ <script type="text/babel">
98
+ const { useState, useEffect, useRef, useCallback } = React;
99
+ const device = "DEVICE_PLACEHOLDER";
100
+ const fmt = v => parseFloat(v).toFixed(2);
101
+ const apiPost = (url, body) => fetch(url, { method:"POST", body }).then(r => { if (!r.ok) return r.json().then(e => { throw new Error(e.detail || "Server error"); }); return r.json(); });
102
+
103
+ function Slider({ label, min, max, step, value, onChange }) {
104
+ return ( <div className="param-row"><span className="param-label">{label}</span><input type="range" min={min} max={max} step={step} value={value} onChange={e => onChange(parseFloat(e.target.value))} /><span className="param-val">{fmt(value)}</span></div> );
105
+ }
106
+
107
+ function FileZone({ label, file, onFile }) {
108
+ const [active, setActive] = useState(false);
109
+ return ( <div><div className="tag mb-1">{label}</div><div className={`file-drop ${active?"active":""}`} onDragOver={e=>{e.preventDefault();setActive(true)}} onDragLeave={()=>setActive(false)} onDrop={e=>{e.preventDefault();setActive(false);onFile(e.dataTransfer.files[0]);}}> <input type="file" accept="audio/*" onChange={e=>onFile(e.target.files[0])} /> {file ? <span style={{color:"var(--green)",fontSize:12}}>โœ“ {file.name}</span> : <span style={{color:"var(--muted)",fontSize:12}}>ุงุณุญุจ ู…ู„ูุงู‹ ุฃูˆ ุงู†ู‚ุฑ</span>} </div></div> );
110
+ }
111
+
112
+ function WaveAnim() { return <div className="waveform">{[1,2,3,4,5,6,7].map(i=><span key={i}/>)}</div>; }
113
+
114
+ function App() {
115
+ const [tab, setTab] = useState("generate");
116
+ const [text, setText] = useState(""); const [lang, setLang] = useState("ar"); const [file1, setFile1] = useState(null); const [file2, setFile2] = useState(null);
117
+ const [temperature, setTemp] = useState(0.75); const [speed, setSpeed] = useState(1.0); const [topK, setTopK] = useState(50); const [topP, setTopP] = useState(0.85); const [repPenalty, setRepPenalty] = useState(5.0); const [splitText, setSplitText] = useState(true);
118
+ const [status, setStatus] = useState("idle"); const [statusMsg, setStatusMsg] = useState(""); const [audioUrl, setAudioUrl] = useState(null); const [audioFilename, setAudioFilename] = useState(null);
119
+ const [history, setHistory] = useState([]); const [voices, setVoices] = useState([]); const [selVoice, setSelVoice] = useState(null); const [saveName, setSaveName] = useState(""); const [saveStatus, setSaveStatus] = useState("");
120
+ const languages = LANGUAGES_JSON;
121
+
122
+ useEffect(() => { fetch("/history").then(r=>r.json()).then(setHistory).catch(()=>{}); fetch("/voices").then(r=>r.json()).then(setVoices).catch(()=>{}); }, []);
123
+
124
+ const generate = async () => {
125
+ if (!text.trim()) return setStatusMsg("ุฃุฏุฎู„ ุงู„ู†ุต ุฃูˆู„ุงู‹.");
126
+ if (!file1 && !selVoice) return setStatusMsg("ูŠุฌุจ ุชุญุฏูŠุฏ ุนูŠู†ุฉ ุตูˆุชูŠุฉ ุฃูˆ ุงุฎุชูŠุงุฑ ุตูˆุช ู…ู† ุงู„ู…ูƒุชุจุฉ.");
127
+ setStatus("running"); setStatusMsg(""); setAudioUrl(null);
128
+ const fd = new FormData();
129
+ fd.append("text", text); fd.append("language", lang); fd.append("temperature", temperature); fd.append("speed", speed); fd.append("top_k", topK); fd.append("top_p", topP); fd.append("repetition_penalty", repPenalty); fd.append("enable_text_splitting", splitText);
130
+ if (file1) fd.append("files", file1); if (file2) fd.append("files", file2); if (selVoice) fd.append("voice_name", selVoice);
131
+ try { const data = await apiPost("/generate", fd); setAudioUrl(`/audio/${data.filename}`); setAudioFilename(data.filename); setStatus("done"); fetch("/history").then(r=>r.json()).then(setHistory).catch(()=>{}); } catch(e) { setStatus("error"); setStatusMsg(e.message); }
132
+ };
133
+
134
+ const saveVoice = async () => {
135
+ if (!saveName.trim() || !file1) return;
136
+ const fd = new FormData(); fd.append("name", saveName.trim()); fd.append("file", file1); if (file2) fd.append("file2", file2);
137
+ try { await apiPost("/voices/save", fd); setSaveStatus("โœ“ ุชู… ุงู„ุญูุธ"); fetch("/voices").then(r=>r.json()).then(setVoices).catch(()=>{}); setTimeout(()=>setSaveStatus(""),2000); } catch(e) { setSaveStatus("ุฎุทุฃ: " + e.message); }
138
+ };
139
+
140
+ const deleteVoice = async name => { await fetch(`/voices/${name}`, {method:"DELETE"}); setVoices(v => v.filter(x=>x!==name)); if (selVoice===name) setSelVoice(null); };
141
+ const isRTL = ["ar","fa","he","ur"].includes(lang);
142
+
143
+ return (
144
+ <div style={{maxWidth:720,margin:"0 auto",padding:"24px 16px",position:"relative",zIndex:1}}>
145
+ <div style={{marginBottom:28,textAlign:"center"}}>
146
+ <div className="tag" style={{marginBottom:6}}>XTTS V2 MULTILINGUAL</div>
147
+ <h1 style={{margin:0,fontSize:26,fontWeight:700,letterSpacing:"-.02em"}}><span className="amber">Voice</span> Studio</h1>
148
+ <div style={{marginTop:8,display:"flex",justifyContent:"center",gap:6}}><span className={`badge ${device==="cuda"?"green":"red"}`}>โ— {device.toUpperCase()}</span><span className="badge">HuggingFace Space</span></div>
149
+ </div>
150
+ <div style={{display:"flex",gap:4,marginBottom:20,background:"var(--surface)",border:"1px solid var(--border)",borderRadius:8,padding:4}}>
151
+ {["generate","library","history"].map(t=>( <div key={t} className={`tab${tab===t?" active":""}`} onClick={()=>setTab(t)} style={{flex:1,textAlign:"center"}}>{t==="generate"?"โšก ุชูˆู„ูŠุฏ":t==="library"?"๐Ÿ“š ู…ูƒุชุจุฉ ุงู„ุฃุตูˆุงุช":"๐Ÿ•˜ ุงู„ุณุฌู„"}</div> ))}
152
+ </div>
153
+ {tab==="generate" && (
154
+ <div style={{display:"flex",flexDirection:"column",gap:14}}>
155
+ <div className="card" style={{padding:16}}><div style={{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10}}><div className="tag">ุงู„ู†ุต ุงู„ู…ุฑุงุฏ ุชุญูˆูŠู„ู‡</div><select value={lang} onChange={e=>setLang(e.target.value)}>{Object.entries(languages).map(([k,v])=><option key={k} value={k}>{v}</option>)}</select></div><textarea dir={isRTL?"rtl":"ltr"} rows={5} placeholder={isRTL?"ุฃุฏุฎู„ ุงู„ู†ุต ู‡ู†ุงโ€ฆ":"Enter text hereโ€ฆ"} value={text} onChange={e=>setText(e.target.value)} /></div>
156
+ <div className="card" style={{padding:16}}><div className="tag" style={{marginBottom:10}}>ุงู„ู…ุฑุฌุน ุงู„ุตูˆุชูŠ</div><div style={{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12}}><FileZone label="ุนูŠู†ุฉ 1 (ู…ุทู„ูˆุจุฉ)" file={file1} onFile={setFile1} /><FileZone label="ุนูŠู†ุฉ 2 (ุงุฎุชูŠุงุฑูŠุฉ)" file={file2} onFile={setFile2} /></div>
157
+ {voices.length>0 && ( <div style={{marginTop:12}}><div className="tag" style={{marginBottom:8}}>ุฃูˆ ู…ู† ุงู„ู…ูƒุชุจุฉ</div><div style={{display:"flex",flexWrap:"wrap",gap:8}}>{voices.map(v=>( <div key={v} style={{padding:"6px 14px",borderRadius:20,cursor:"pointer",fontSize:12,border:"1px solid",borderColor:selVoice===v?"var(--amber)":"var(--border)",color:selVoice===v?"var(--amber)":"var(--muted)",background:selVoice===v?"rgba(245,166,35,.08)":"transparent",transition:"all .2s"}} onClick={()=>setSelVoice(selVoice===v?null:v)}>{v}</div> ))}</div></div> )}
158
+ {file1 && ( <div style={{marginTop:12,display:"flex",gap:8,alignItems:"center"}}><input type="text" placeholder="ุงุณู… ุงู„ุตูˆุช ู„ู„ุญูุธโ€ฆ" value={saveName} onChange={e=>setSaveName(e.target.value)} style={{flex:1,background:"var(--bg)",border:"1px solid var(--border)",color:"var(--text)",borderRadius:6,padding:"6px 10px",fontSize:12,fontFamily:"var(--sans)",outline:"none"}} /><button className="btn-ghost" onClick={saveVoice} style={{whiteSpace:"nowrap"}}>ุญูุธ ููŠ ุงู„ู…ูƒุชุจุฉ</button>{saveStatus && <span style={{fontSize:12,color:"var(--green)"}}>{saveStatus}</span>}</div> )}
159
+ </div>
160
+ <div className="card" style={{padding:16}}><details><summary style={{cursor:"pointer",listStyle:"none",display:"flex",justifyContent:"space-between",alignItems:"center",userSelect:"none"}}><div className="tag">ุงู„ู…ุนุงู…ู„ุงุช ุงู„ู…ุชู‚ุฏู…ุฉ</div><span style={{fontSize:11,color:"var(--muted)"}}>ุงู†ู‚ุฑ ู„ู„ุชูˆุณูŠุน โ–พ</span></summary><div style={{marginTop:14,display:"flex",flexDirection:"column",gap:14}}><Slider label="temperature" min={0.05} max={1.0} step={0.05} value={temperature} onChange={setTemp} /><Slider label="speed" min={0.5} max={2.0} step={0.05} value={speed} onChange={setSpeed} /><Slider label="top_k" min={1} max={100} step={1} value={topK} onChange={setTopK} /><Slider label="top_p" min={0.1} max={1.0} step={0.05} value={topP} onChange={setTopP} /><Slider label="rep_penalty" min={1.0} max={10.0} step={0.5} value={repPenalty} onChange={setRepPenalty} /></div></details></div>
161
+ {statusMsg && <div style={{padding:"10px 14px",borderRadius:8,fontSize:13,background:"rgba(255,82,82,.08)",border:"1px solid rgba(255,82,82,.3)",color:"var(--red)"}}>{statusMsg}</div>}
162
+ <button className="btn-primary" onClick={generate} disabled={status==="running"}>{status==="running" ? <span style={{display:"flex",alignItems:"center",justifyContent:"center",gap:10}}><WaveAnim/> ุฌุงุฑูŠ ุงู„ุชูˆู„ูŠุฏโ€ฆ</span> : "โšก ุชูˆู„ูŠุฏ ุงู„ุตูˆุช"}</button>
163
+ {audioUrl && ( <div className="card" style={{padding:16}}><div style={{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12}}><div style={{display:"flex",alignItems:"center",gap:8}}><span className="badge green">โœ“ ุชู… ุงู„ุชูˆู„ูŠุฏ</span></div><a href={audioUrl} download={audioFilename} style={{textDecoration:"none"}}><button className="btn-ghost">โฌ‡ ุชุญู…ูŠู„</button></a></div><audio src={audioUrl} controls autoPlay /></div> )}
164
+ </div>
165
+ )}
166
+ {tab==="library" && (
167
+ <div style={{display:"flex",flexDirection:"column",gap:12}}>
168
+ <div className="card" style={{padding:16}}><div className="tag" style={{marginBottom:8}}>ุฅุถุงูุฉ ุตูˆุช ุฌุฏูŠุฏ ู„ู„ู…ูƒุชุจุฉ</div><div style={{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,marginBottom:12}}><FileZone label="ุนูŠู†ุฉ 1" file={file1} onFile={setFile1} /><FileZone label="ุนูŠู†ุฉ 2 (ุงุฎุชูŠุงุฑูŠ)" file={file2} onFile={setFile2} /></div><div style={{display:"flex",gap:8}}><input type="text" placeholder="ุงุณู… ุงู„ุตูˆุชโ€ฆ" value={saveName} onChange={e=>setSaveName(e.target.value)} style={{flex:1,background:"var(--bg)",border:"1px solid var(--border)",color:"var(--text)",borderRadius:6,padding:"8px 12px",fontSize:13,fontFamily:"var(--sans)",outline:"none"}} /><button className="btn-primary" style={{width:"auto",padding:"8px 20px"}} onClick={saveVoice}>ุญูุธ</button></div>{saveStatus && <div style={{marginTop:8,fontSize:12,color:"var(--green)"}}>{saveStatus}</div>}</div>
169
+ {voices.length===0 ? <div style={{textAlign:"center",color:"var(--muted)",padding:"40px 0",fontSize:14}}>ู„ุง ุชูˆุฌุฏ ุฃุตูˆุงุช ู…ุญููˆุธุฉ ุจุนุฏ.</div> : voices.map(v=>( <div key={v} className="voice-card" onClick={()=>{setSelVoice(selVoice===v?null:v);setTab("generate");}}><div><div style={{fontSize:14,fontWeight:600}}>{v}</div><div style={{fontSize:11,color:"var(--muted)",marginTop:2,fontFamily:"var(--mono)"}}>{selVoice===v?"โ— ู…ุญุฏุฏ":"ุงู†ู‚ุฑ ู„ู„ุงุณุชุฎุฏุงู…"}</div></div><button className="btn-ghost" onClick={e=>{e.stopPropagation();deleteVoice(v);}}>ุญุฐู</button></div> ))}
170
+ </div>
171
+ )}
172
+ {tab==="history" && (
173
+ <div style={{display:"flex",flexDirection:"column",gap:10}}>
174
+ {history.length===0 ? <div style={{textAlign:"center",color:"var(--muted)",padding:"40px 0",fontSize:14}}>ุงู„ุณุฌู„ ูุงุฑุบ.</div> : [...history].reverse().map((h,i)=>( <div key={i} className="history-row"><div style={{flex:1,minWidth:0}}><div style={{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",direction:"rtl"}}>{h.text}</div><div style={{display:"flex",gap:8,marginTop:4,flexWrap:"wrap"}}><span className="badge">{h.language}</span><span style={{fontSize:10,color:"var(--muted)",fontFamily:"var(--mono)"}}>{new Date(h.ts*1000).toLocaleString("ar-EG")}</span></div></div><div style={{display:"flex",gap:6,flexShrink:0}}><button className="btn-ghost" onClick={()=>{setAudioUrl(`/audio/${h.filename}`);setAudioFilename(h.filename);setTab("generate");setStatus("done");}}></button><a href={`/audio/${h.filename}`} download={h.filename} style={{textDecoration:"none"}}><button className="btn-ghost">โฌ‡</button></a></div></div> ))}
175
+ </div>
176
+ )}
177
+ </div>
178
+ );
179
+ }
180
+ ReactDOM.createRoot(document.getElementById("root")).render(<App/>);
181
+ </script>
182
+ </body>
183
+ </html>
184
+ """
185
+
186
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
187
+ # Routes
188
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
189
+
190
+ @app.get("/", response_class=HTMLResponse)
191
+ async def ui():
192
+ page = (
193
+ HTML
194
+ .replace("LANGUAGES_JSON", json.dumps(LANGUAGES, ensure_ascii=False))
195
+ .replace("DEVICE_PLACEHOLDER", device)
196
+ )
197
+ return page
198
+
199
+
200
+ @app.post("/generate")
201
+ async def generate(
202
+ text: str = Form(...),
203
+ language: str = Form("ar"),
204
+ temperature: float = Form(0.75),
205
+ speed: float = Form(1.0),
206
+ top_k: int = Form(50),
207
+ top_p: float = Form(0.85),
208
+ repetition_penalty: float = Form(5.0),
209
+ enable_text_splitting: bool = Form(True),
210
+ voice_name: str = Form(None),
211
+ files: list[UploadFile] = File(default=[]),
212
+ ):
213
+ if not text.strip():
214
+ raise HTTPException(400, "ุงู„ู†ุต ูุงุฑุบ.")
215
+
216
+ ref_paths, tmp_files = [], []
217
+ for f in files:
218
+ path = f"/tmp/ref_{uuid.uuid4().hex}_{f.filename}"
219
+ with open(path, "wb") as buf:
220
+ shutil.copyfileobj(f.file, buf)
221
+ ref_paths.append(path)
222
+ tmp_files.append(path)
223
+
224
+ if voice_name:
225
+ lib_dir = os.path.join(VOICE_LIB, voice_name)
226
+ if os.path.isdir(lib_dir):
227
+ ref_paths += [
228
+ os.path.join(lib_dir, fn)
229
+ for fn in os.listdir(lib_dir)
230
+ if fn.lower().endswith((".wav", ".mp3", ".flac", ".ogg"))
231
+ ]
232
+
233
+ if not ref_paths:
234
+ raise HTTPException(400, "ูŠุฌุจ ุชุญุฏูŠุฏ ุนูŠู†ุฉ ุตูˆุชูŠุฉ ู…ุฑุฌุนูŠุฉ.")
235
+
236
+ out_name = f"gen_{uuid.uuid4().hex[:8]}.wav"
237
+ out_path = os.path.join(OUTPUT_DIR, out_name)
238
+
239
+ try:
240
+ xtts_engine.tts_to_file(
241
+ text=text,
242
+ speaker_wav=ref_paths,
243
+ language=language,
244
+ file_path=out_path,
245
+ temperature=float(temperature),
246
+ speed=float(speed),
247
+ top_k=int(top_k),
248
+ top_p=float(top_p),
249
+ repetition_penalty=float(repetition_penalty),
250
+ enable_text_splitting=bool(enable_text_splitting),
251
+ )
252
+ finally:
253
+ for p in tmp_files:
254
+ try:
255
+ os.remove(p)
256
+ except Exception:
257
+ pass
258
+
259
+ hist = load_history()
260
+ hist.append({"filename": out_name, "text": text[:120], "language": language, "ts": int(time.time())})
261
+ save_history(hist)
262
+ return {"filename": out_name}
263
+
264
+
265
+ @app.get("/audio/{filename}")
266
+ def get_audio(filename: str):
267
+ path = os.path.join(OUTPUT_DIR, filename)
268
+ if not os.path.exists(path):
269
+ raise HTTPException(404, "File not found.")
270
+ return FileResponse(path, media_type="audio/wav")
271
+
272
+
273
+ @app.get("/history")
274
+ def get_history():
275
+ return JSONResponse(load_history())
276
+
277
+
278
+ @app.get("/voices")
279
+ def list_voices():
280
+ if not os.path.isdir(VOICE_LIB):
281
+ return []
282
+ return [d for d in os.listdir(VOICE_LIB) if os.path.isdir(os.path.join(VOICE_LIB, d))]
283
+
284
+
285
+ @app.post("/voices/save")
286
+ async def save_voice(
287
+ name: str = Form(...),
288
+ file: UploadFile = File(...),
289
+ file2: UploadFile = File(default=None),
290
+ ):
291
+ safe = name.strip().replace("/", "_").replace("..", "_")
292
+ lib_dir = os.path.join(VOICE_LIB, safe)
293
+ os.makedirs(lib_dir, exist_ok=True)
294
+ for f in ([file, file2] if file2 else [file]):
295
+ with open(os.path.join(lib_dir, f.filename), "wb") as buf:
296
+ shutil.copyfileobj(f.file, buf)
297
+ return {"name": safe}
298
+
299
+
300
+ @app.delete("/voices/{name}")
301
+ def delete_voice(name: str):
302
+ lib_dir = os.path.join(VOICE_LIB, name)
303
+ if os.path.isdir(lib_dir):
304
+ shutil.rmtree(lib_dir)
305
+ return {"deleted": name}
306
+
307
+
308
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•๏ฟฝ๏ฟฝโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
309
+ # Entry point (used by Dockerfile CMD)
310
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
311
+ if __name__ == "__main__":
312
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
requirements (6).txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # TTS engine
2
+ coqui-tts>=0.22.0
3
+
4
+ # Web framework
5
+ fastapi>=0.111.0
6
+ uvicorn[standard]>=0.29.0
7
+ python-multipart>=0.0.9
8
+
9
+ # PyTorch CPU-only wheel (much smaller image, sufficient for inference)
10
+ torch>=2.2.0
11
+ torchaudio>=2.2.0