File size: 1,978 Bytes
fd13a7c
 
24bb896
fd13a7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24bb896
fd13a7c
 
24bb896
fd13a7c
 
 
24bb896
 
fd13a7c
 
24bb896
fd13a7c
 
 
 
 
 
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
"""
MockMate AI — Free Hugging Face Spaces Entrypoint (Gradio SDK)
Mounts FastAPI backend and serves full React UI on port 7860.
"""
import os
import sys
import urllib.request
from pathlib import Path

# Paths setup
ROOT_DIR = Path(__file__).resolve().parent
MOCKMATE_DIR = ROOT_DIR / "mockmate"
MODELS_DIR = MOCKMATE_DIR / "models"

sys.path.insert(0, str(ROOT_DIR))
sys.path.insert(0, str(MOCKMATE_DIR))

# Download Kokoro TTS models if missing
KOKORO_MODEL = MODELS_DIR / "kokoro-v1.0.onnx"
KOKORO_VOICES = MODELS_DIR / "voices-v1.0.bin"

if not KOKORO_MODEL.exists() or not KOKORO_VOICES.exists():
    print("[1/2] Kokoro TTS models missing. Downloading for Hugging Face Space...")
    MODELS_DIR.mkdir(parents=True, exist_ok=True)
    if not KOKORO_MODEL.exists():
        print(" -> Downloading kokoro-v1.0.onnx...")
        urllib.request.urlretrieve(
            "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.0/kokoro-v1.0.onnx",
            str(KOKORO_MODEL)
        )
    if not KOKORO_VOICES.exists():
        print(" -> Downloading voices-v1.0.bin...")
        urllib.request.urlretrieve(
            "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.0/voices-v1.0.bin",
            str(KOKORO_VOICES)
        )
    print("✓ Models downloaded.")

# Change directory to mockmate for relative imports and static assets
os.chdir(str(MOCKMATE_DIR))

# Import FastAPI backend
from main import app as fastapi_app
import gradio as gr

# Create Gradio blocks wrapper
with gr.Blocks(title="MockMate AI - Interview Coach", css="body { background: #0b0f19; }") as demo:
    gr.HTML('<iframe src="/" style="width:100%; height:900px; border:none; background: #0b0f19;"></iframe>')

# Mount Gradio into FastAPI app
app = gr.mount_gradio_app(fastapi_app, demo, path="/gradio")

if __name__ == "__main__":
    import uvicorn
    port = int(os.environ.get("PORT", 7860))
    uvicorn.run(app, host="0.0.0.0", port=port)