Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
import time
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
# HF Spaces environment variables
|
| 10 |
+
SPACE_ID = os.getenv("SPACE_ID", "broadfield-dev/voxtral-local")
|
| 11 |
+
HF_TOKEN = os.getenv("HF_TOKEN") # Optional, for private models if needed
|
| 12 |
+
|
| 13 |
+
# Configuration
|
| 14 |
+
PORT = 7860 # Gradio default on HF Spaces
|
| 15 |
+
HOST = "0.0.0.0"
|
| 16 |
+
|
| 17 |
+
print("🚀 Starting Voxtral TTS Gradio Demo on Hugging Face Spaces...")
|
| 18 |
+
|
| 19 |
+
# Step 1: Clone the repository (if not already present)
|
| 20 |
+
repo_dir = Path("vllm-omni")
|
| 21 |
+
if not repo_dir.exists():
|
| 22 |
+
print("Cloning vllm-omni repository...")
|
| 23 |
+
subprocess.run(
|
| 24 |
+
["git", "clone", "https://github.com/vllm-project/vllm-omni.git"],
|
| 25 |
+
check=True
|
| 26 |
+
)
|
| 27 |
+
else:
|
| 28 |
+
print("Repository already cloned.")
|
| 29 |
+
|
| 30 |
+
os.chdir(repo_dir)
|
| 31 |
+
|
| 32 |
+
# Step 2: Install dependencies
|
| 33 |
+
# Note: HF Spaces uses uv or pip; we use uv as in the original command
|
| 34 |
+
print("Installing dependencies with uv...")
|
| 35 |
+
subprocess.run(["uv", "pip", "install", "gradio==5.50"], check=True)
|
| 36 |
+
|
| 37 |
+
# Install vllm-omni from source (recommended by the model authors)
|
| 38 |
+
print("Installing vllm-omni from source...")
|
| 39 |
+
subprocess.run(
|
| 40 |
+
["uv", "pip", "install", "-e", "."],
|
| 41 |
+
check=True
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Additional common dependencies for audio/TTS (soundfile, etc.)
|
| 45 |
+
subprocess.run(
|
| 46 |
+
["uv", "pip", "install", "soundfile", "numpy"],
|
| 47 |
+
check=True
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
print("✅ Dependencies installed.")
|
| 51 |
+
|
| 52 |
+
# Step 3: Launch the Gradio demo
|
| 53 |
+
print(f"Launching Gradio demo on http://{HOST}:{PORT} ...")
|
| 54 |
+
|
| 55 |
+
# We run the demo script in a subprocess so the main thread can keep the Space alive
|
| 56 |
+
# The original command uses --host and --port; we adapt for HF Spaces (0.0.0.0 + 7860)
|
| 57 |
+
cmd = [
|
| 58 |
+
sys.executable,
|
| 59 |
+
"examples/online_serving/voxtral_tts/gradio_demo.py",
|
| 60 |
+
"--host", HOST,
|
| 61 |
+
"--port", str(PORT),
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
# Optional: add other flags if the script supports them (e.g. model path, etc.)
|
| 65 |
+
# cmd.extend(["--model", "mistralai/Voxtral-4B-TTS-2603"]) # if needed
|
| 66 |
+
|
| 67 |
+
print("Running command:", " ".join(cmd))
|
| 68 |
+
|
| 69 |
+
# Launch the process
|
| 70 |
+
process = subprocess.Popen(
|
| 71 |
+
cmd,
|
| 72 |
+
stdout=sys.stdout,
|
| 73 |
+
stderr=sys.stderr,
|
| 74 |
+
env=os.environ.copy()
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
# Keep the main process alive (required for HF Spaces)
|
| 78 |
+
try:
|
| 79 |
+
while True:
|
| 80 |
+
time.sleep(60) # Check every minute
|
| 81 |
+
if process.poll() is not None:
|
| 82 |
+
print("⚠️ Gradio process exited unexpectedly.")
|
| 83 |
+
break
|
| 84 |
+
except KeyboardInterrupt:
|
| 85 |
+
print("Shutting down...")
|
| 86 |
+
process.terminate()
|