File size: 2,409 Bytes
a7193e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import subprocess
import sys
import time
from pathlib import Path

import gradio as gr

# HF Spaces environment variables
SPACE_ID = os.getenv("SPACE_ID", "broadfield-dev/voxtral-local")
HF_TOKEN = os.getenv("HF_TOKEN")  # Optional, for private models if needed

# Configuration
PORT = 7860  # Gradio default on HF Spaces
HOST = "0.0.0.0"

print("🚀 Starting Voxtral TTS Gradio Demo on Hugging Face Spaces...")

# Step 1: Clone the repository (if not already present)
repo_dir = Path("vllm-omni")
if not repo_dir.exists():
    print("Cloning vllm-omni repository...")
    subprocess.run(
        ["git", "clone", "https://github.com/vllm-project/vllm-omni.git"],
        check=True
    )
else:
    print("Repository already cloned.")

os.chdir(repo_dir)

# Step 2: Install dependencies
# Note: HF Spaces uses uv or pip; we use uv as in the original command
print("Installing dependencies with uv...")
subprocess.run(["uv", "pip", "install", "gradio==5.50"], check=True)

# Install vllm-omni from source (recommended by the model authors)
print("Installing vllm-omni from source...")
subprocess.run(
    ["uv", "pip", "install", "-e", "."],
    check=True
)

# Additional common dependencies for audio/TTS (soundfile, etc.)
subprocess.run(
    ["uv", "pip", "install", "soundfile", "numpy"],
    check=True
)

print("✅ Dependencies installed.")

# Step 3: Launch the Gradio demo
print(f"Launching Gradio demo on http://{HOST}:{PORT} ...")

# We run the demo script in a subprocess so the main thread can keep the Space alive
# The original command uses --host and --port; we adapt for HF Spaces (0.0.0.0 + 7860)
cmd = [
    sys.executable,
    "examples/online_serving/voxtral_tts/gradio_demo.py",
    "--host", HOST,
    "--port", str(PORT),
]

# Optional: add other flags if the script supports them (e.g. model path, etc.)
# cmd.extend(["--model", "mistralai/Voxtral-4B-TTS-2603"])  # if needed

print("Running command:", " ".join(cmd))

# Launch the process
process = subprocess.Popen(
    cmd,
    stdout=sys.stdout,
    stderr=sys.stderr,
    env=os.environ.copy()
)

# Keep the main process alive (required for HF Spaces)
try:
    while True:
        time.sleep(60)  # Check every minute
        if process.poll() is not None:
            print("⚠️  Gradio process exited unexpectedly.")
            break
except KeyboardInterrupt:
    print("Shutting down...")
    process.terminate()