Update app.py
Browse files180 unmodified lines181182183184185186187188189190191192193194195196197198199200201202203204205206207208180 unmodified linesreturn await run_task(request, "generate-kpis")with gr.Blocks(title="منصة الأداء", css="""html, body { margin:0 !important; padding:0 !important; }.gradio-container { max-width:100% !important; width:100% !important; margin:0 !important; padding:0 !important; }#kpi-frontend { width:100%; height:100vh; overflow:hidden; }""") as demo:gr.HTML('<iframe id="kpi-frontend" src="/custom-ui" title="منصة الأداء" style="width:100%;height:100vh;border:0;display:block;background:#f8fafc"></iframe>')# Add the frontend and API routes to the same Gradio/FastAPI app.routes = [Route("/custom-ui", serve_ui, methods=["GET"]),Route("/style.css", serve_css, methods=["GET"]),Route("/script.js", serve_js, methods=["GET"]),Route("/data_ar.json", serve_data_ar, methods=["GET"]),Route("/data_en.json", serve_data_en, methods=["GET"]),Route("/api/insights", insights, methods=["POST"]),Route("/api/generate-kpis", generate_kpis, methods=["POST"]),]for route in reversed(routes):demo.app.router.routes.insert(0, route)if __name__ == "__main__":demo.queue(default_concurrency_limit=1).launch(server_name="0.0.0.0",server_port=int(os.getenv("PORT", "7860")),)180 unmodified lines181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233180 unmodified linesreturn await run_task(request, "generate-kpis")# Serve the custom frontend directly using Gradio Server mode.app = gr.Server()@app.get("/")async def homepage():return file_response(INDEX_FILE, "text/html; charset=utf-8")@app.get("/custom-ui")async def serve_custom_ui():return file_response(INDEX_FILE, "text/html; charset=utf-8")@app.get("/style.css")async def serve_stylesheet():return file_response(CSS_FILE, "text/css; charset=utf-8")@app.get("/script.js")async def serve_javascript():return file_response(JS_FILE, "application/javascript; charset=utf-8")@app.get("/data_ar.json")async def serve_arabic_data():return file_response(DATA_AR_FILE, "application/json")@app.get("/data_en.json")async def serve_english_data():return file_response(DATA_EN_FILE, "application/json")@app.post("/api/insights")async def insights_endpoint(request: Request):return await run_task(request, "insights")@app.post("/api/generate-kpis")async def generate_kpis_endpoint(request: Request):return await run_task(request, "generate-kpis")if __name__ == "__main__":app.launch(server_name="0.0.0.0",server_port=int(os.getenv("PORT", "7860")),)
app.py+45-20