import os from gradio import Server from fastapi.responses import HTMLResponse, FileResponse from fastapi.staticfiles import StaticFiles app = Server(title="Heartline ") _here = os.path.dirname(os.path.abspath(__file__)) app.mount("/samples", StaticFiles(directory=os.path.join(_here, "samples")), name="samples") @app.get("/heartline.onnx") async def serve_model() -> FileResponse: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "heartline.onnx") return FileResponse(path, media_type="application/octet-stream") @app.get("/constants.js") async def serve_constants() -> FileResponse: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "constants.js") return FileResponse(path, media_type="application/javascript") @app.api_route("/model_Q4_K_M.gguf", methods=["GET", "HEAD"]) async def serve_gguf() -> FileResponse: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "model_Q4_K_M.gguf") return FileResponse(path, media_type="application/octet-stream") @app.get("/") async def homepage() -> HTMLResponse: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "index.html") with open(path, "r", encoding="utf-8") as f: return HTMLResponse(f.read()) app.launch(server_name="0.0.0.0", server_port=7860, show_error=True, _frontend=False)