MohdUmar0223 commited on
Commit
fd5f85d
·
verified ·
1 Parent(s): 10ea7fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -287,24 +287,24 @@ def register_api_routes(gradio_app):
287
  })
288
 
289
 
 
 
 
290
  # Register REST API routes on the Gradio underlying FastAPI app
291
  try:
292
  from fastapi.middleware.cors import CORSMiddleware
293
  # Explicitly configure CORS on the underlying FastAPI app to allow direct requests from the browser
294
- demo.app.add_middleware(
295
  CORSMiddleware,
296
  allow_origins=["*"],
297
  allow_credentials=True,
298
  allow_methods=["*"],
299
  allow_headers=["*"],
300
  )
301
- register_api_routes(demo.app)
302
  logger.info("CORS middleware and REST API routes registered successfully on Gradio FastAPI app.")
303
  except Exception as e:
304
- logger.warning(f"Could not register REST API routes or CORS (will be available via Gradio only): {e}")
305
-
306
- # Export Gradio demo as root app object for Hugging Face ZeroGPU SDK
307
- app = demo
308
 
309
  if __name__ == "__main__":
310
  # Local development only — on HF Spaces, uvicorn runs the app directly
 
287
  })
288
 
289
 
290
+ # Create the FastAPI app instance from Gradio Blocks
291
+ app = demo.create_app()
292
+
293
  # Register REST API routes on the Gradio underlying FastAPI app
294
  try:
295
  from fastapi.middleware.cors import CORSMiddleware
296
  # Explicitly configure CORS on the underlying FastAPI app to allow direct requests from the browser
297
+ app.add_middleware(
298
  CORSMiddleware,
299
  allow_origins=["*"],
300
  allow_credentials=True,
301
  allow_methods=["*"],
302
  allow_headers=["*"],
303
  )
304
+ register_api_routes(app)
305
  logger.info("CORS middleware and REST API routes registered successfully on Gradio FastAPI app.")
306
  except Exception as e:
307
+ logger.warning(f"Could not register REST API routes or CORS: {e}")
 
 
 
308
 
309
  if __name__ == "__main__":
310
  # Local development only — on HF Spaces, uvicorn runs the app directly