Spaces:
Running on Zero

seed-image-ai commited on
Commit
d2adcff
·
verified ·
1 Parent(s): abcf340

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -20
app.py CHANGED
@@ -181,28 +181,53 @@ async def generate_kpis(request: Request):
181
  return await run_task(request, "generate-kpis")
182
 
183
 
184
- with gr.Blocks(title="منصة الأداء", css="""
185
- html, body { margin:0 !important; padding:0 !important; }
186
- .gradio-container { max-width:100% !important; width:100% !important; margin:0 !important; padding:0 !important; }
187
- #kpi-frontend { width:100%; height:100vh; overflow:hidden; }
188
- """) as demo:
189
- gr.HTML('<iframe id="kpi-frontend" src="/custom-ui" title="منصة الأداء" style="width:100%;height:100vh;border:0;display:block;background:#f8fafc"></iframe>')
190
-
191
- # Add the frontend and API routes to the same Gradio/FastAPI app.
192
- routes = [
193
- Route("/custom-ui", serve_ui, methods=["GET"]),
194
- Route("/style.css", serve_css, methods=["GET"]),
195
- Route("/script.js", serve_js, methods=["GET"]),
196
- Route("/data_ar.json", serve_data_ar, methods=["GET"]),
197
- Route("/data_en.json", serve_data_en, methods=["GET"]),
198
- Route("/api/insights", insights, methods=["POST"]),
199
- Route("/api/generate-kpis", generate_kpis, methods=["POST"]),
200
- ]
201
- for route in reversed(routes):
202
- demo.app.router.routes.insert(0, route)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
  if __name__ == "__main__":
205
- demo.queue(default_concurrency_limit=1).launch(
206
  server_name="0.0.0.0",
207
  server_port=int(os.getenv("PORT", "7860")),
208
  )
 
 
181
  return await run_task(request, "generate-kpis")
182
 
183
 
184
+ # Serve the custom frontend directly using Gradio Server mode.
185
+ app = gr.Server()
186
+
187
+
188
+ @app.get("/")
189
+ async def homepage():
190
+ return file_response(INDEX_FILE, "text/html; charset=utf-8")
191
+
192
+
193
+ @app.get("/custom-ui")
194
+ async def serve_custom_ui():
195
+ return file_response(INDEX_FILE, "text/html; charset=utf-8")
196
+
197
+
198
+ @app.get("/style.css")
199
+ async def serve_stylesheet():
200
+ return file_response(CSS_FILE, "text/css; charset=utf-8")
201
+
202
+
203
+ @app.get("/script.js")
204
+ async def serve_javascript():
205
+ return file_response(JS_FILE, "application/javascript; charset=utf-8")
206
+
207
+
208
+ @app.get("/data_ar.json")
209
+ async def serve_arabic_data():
210
+ return file_response(DATA_AR_FILE, "application/json")
211
+
212
+
213
+ @app.get("/data_en.json")
214
+ async def serve_english_data():
215
+ return file_response(DATA_EN_FILE, "application/json")
216
+
217
+
218
+ @app.post("/api/insights")
219
+ async def insights_endpoint(request: Request):
220
+ return await run_task(request, "insights")
221
+
222
+
223
+ @app.post("/api/generate-kpis")
224
+ async def generate_kpis_endpoint(request: Request):
225
+ return await run_task(request, "generate-kpis")
226
+
227
 
228
  if __name__ == "__main__":
229
+ app.launch(
230
  server_name="0.0.0.0",
231
  server_port=int(os.getenv("PORT", "7860")),
232
  )
233
+