MOCKMATE / app.py
sriyanshcodes-dev
Include React production build for Hugging Face Spaces deployment
24bb896
Raw History Blame Contribute Delete
1.98 kB
"""
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)