Spaces:
Running on Zero
Running on Zero
File size: 2,402 Bytes
bf90f9f f02ea72 bf90f9f aaf69fe bf90f9f f02ea72 bf90f9f aaf69fe f02ea72 aaf69fe f02ea72 aaf69fe bf90f9f cdccb11 f02ea72 cdccb11 f02ea72 cdccb11 f02ea72 cdccb11 f02ea72 | 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 | import os
import threading
import gradio as gr
# Configure cloud defaults for Hugging Face Spaces (Gradio SDK, ZeroGPU Free)
os.environ.setdefault("LLM_PROVIDER", "gemini")
os.environ.setdefault("LLM_FALLBACK_PROVIDER", "gemini")
os.environ.setdefault("WHISPER_MODEL", "large-v3-turbo")
os.environ.setdefault("WHISPER_DEVICE", "cpu")
os.environ.setdefault("WHISPER_COMPUTE_TYPE", "int8")
os.environ.setdefault("WHISPER_BEAM_SIZE", "1")
os.environ.setdefault("CORS_ORIGINS", "*")
import create_tables # noqa: E402, F401
from fastapi.exceptions import RequestValidationError # noqa: E402
from starlette.exceptions import HTTPException as StarletteHTTPException # noqa: E402
from app.api.v1.router import api_router # noqa: E402
from app.utils.errors import ( # noqa: E402
AppError,
app_error_handler,
validation_error_handler,
http_error_handler,
generic_error_handler,
)
try:
import spaces
@spaces.GPU
def _zerogpu_ping():
return "TuneChecker ZeroGPU Ready"
except Exception:
def _zerogpu_ping():
return "TuneChecker CPU Ready"
with gr.Blocks(title="TuneChecker API") as demo:
gr.Markdown("# TuneChecker Sales Call Quality Auditor API")
gr.Markdown("API Base: `/api/v1` · Health: `/api/v1/health`")
btn = gr.Button("Check Runtime")
out = gr.Textbox(label="Status")
btn.click(_zerogpu_ping, outputs=out)
if __name__ == "__main__":
# Let Gradio bind the exact port expected by Hugging Face ZeroGPU (ssr_mode=False so Python serves /api/v1 directly)
demo.launch(server_name="0.0.0.0", ssr_mode=False, prevent_thread_lock=True)
# Attach TuneChecker FastAPI routes & handlers directly to Gradio's FastAPI app
# Prepend our /api/v1 routes BEFORE Gradio's catch-all UI routes
fastapi_app = demo.app
fastapi_app.add_exception_handler(AppError, app_error_handler)
fastapi_app.add_exception_handler(RequestValidationError, validation_error_handler)
fastapi_app.add_exception_handler(StarletteHTTPException, http_error_handler)
fastapi_app.add_exception_handler(Exception, generic_error_handler)
existing_count = len(fastapi_app.router.routes)
fastapi_app.include_router(api_router, prefix="/api/v1")
new_routes = fastapi_app.router.routes[existing_count:]
fastapi_app.router.routes[:] = new_routes + fastapi_app.router.routes[:existing_count]
threading.Event().wait()
|