qqwjq1981 commited on
Commit
25e956c
·
verified ·
1 Parent(s): e555910

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -1137,9 +1137,14 @@ gradio_asgi_app = gr.routes.App.create_app(demo)
1137
  # Mount the Gradio ASGI app at "/gradio"
1138
  app.mount("/gradio", gradio_asgi_app)
1139
 
1140
- # Mount static files for Gradio assets
1141
  gradio_assets_path = os.path.join(os.path.dirname(gr.__file__), "static")
1142
- app.mount("/assets", StaticFiles(directory=gradio_assets_path), name="assets")
 
 
 
 
 
1143
 
1144
  # Redirect from the root endpoint to the Gradio app
1145
  @app.get("/", response_class=RedirectResponse)
@@ -1149,4 +1154,4 @@ async def index():
1149
  # Run the FastAPI server using uvicorn
1150
  if __name__ == "__main__":
1151
  port = int(os.getenv("PORT", 7860)) # Default to 7860 if PORT is not set
1152
- uvicorn.run(app, host="0.0.0.0", port=port)
 
1137
  # Mount the Gradio ASGI app at "/gradio"
1138
  app.mount("/gradio", gradio_asgi_app)
1139
 
1140
+ # Dynamically check for the Gradio asset directory
1141
  gradio_assets_path = os.path.join(os.path.dirname(gr.__file__), "static")
1142
+
1143
+ if os.path.exists(gradio_assets_path):
1144
+ # If assets exist, mount them
1145
+ app.mount("/assets", StaticFiles(directory=gradio_assets_path), name="assets")
1146
+ else:
1147
+ logging.error(f"Gradio assets directory not found at: {gradio_assets_path}")
1148
 
1149
  # Redirect from the root endpoint to the Gradio app
1150
  @app.get("/", response_class=RedirectResponse)
 
1154
  # Run the FastAPI server using uvicorn
1155
  if __name__ == "__main__":
1156
  port = int(os.getenv("PORT", 7860)) # Default to 7860 if PORT is not set
1157
+ uvicorn.run(app, host="0.0.0.0", port=port)