petter2025 commited on
Commit
4fb793e
·
verified ·
1 Parent(s): 5335a6e

Update hf_demo.py

Browse files
Files changed (1) hide show
  1. hf_demo.py +22 -16
hf_demo.py CHANGED
@@ -1171,24 +1171,30 @@ if __name__ == "__main__":
1171
  # Mount FastAPI on the Gradio app if available
1172
  if FASTAPI_AVAILABLE:
1173
  print("🔄 Mounting FastAPI endpoints on Gradio app...")
 
1174
  app = mount_gradio_app(api_app, demo, path="/")
1175
  print("✅ FastAPI endpoints mounted successfully")
1176
  print(" Access API at: https://petter2025-agentic-reliability-framework.hf.space/api/v1/...")
 
 
 
 
 
1177
  else:
1178
- app = demo
1179
-
1180
- # Launch the combined app
1181
- app.launch(
1182
- server_name="0.0.0.0",
1183
- server_port=7860,
1184
- share=False,
1185
- debug=False,
1186
- prevent_thread_lock=True,
1187
- show_error=True,
1188
- quiet=False
1189
- )
1190
 
1191
- # Keep the app alive
1192
- import time
1193
- while True:
1194
- time.sleep(1)
 
 
1171
  # Mount FastAPI on the Gradio app if available
1172
  if FASTAPI_AVAILABLE:
1173
  print("🔄 Mounting FastAPI endpoints on Gradio app...")
1174
+ # This returns a FastAPI app that includes both FastAPI routes and Gradio
1175
  app = mount_gradio_app(api_app, demo, path="/")
1176
  print("✅ FastAPI endpoints mounted successfully")
1177
  print(" Access API at: https://petter2025-agentic-reliability-framework.hf.space/api/v1/...")
1178
+
1179
+ # For FastAPI app, we need to use uvicorn to run it
1180
+ import uvicorn
1181
+ print("🚀 Starting combined FastAPI+Gradio server on port 7860...")
1182
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
1183
  else:
1184
+ # Fallback to Gradio-only mode
1185
+ print("⚠️ FastAPI not available, running Gradio only")
1186
+ demo.launch(
1187
+ server_name="0.0.0.0",
1188
+ server_port=7860,
1189
+ share=False,
1190
+ debug=False,
1191
+ prevent_thread_lock=True,
1192
+ show_error=True,
1193
+ quiet=False
1194
+ )
 
1195
 
1196
+ # Keep the app alive (only needed for Gradio fallback)
1197
+ if not FASTAPI_AVAILABLE:
1198
+ import time
1199
+ while True:
1200
+ time.sleep(1)