Update hf_demo.py
Browse files- hf_demo.py +19 -18
hf_demo.py
CHANGED
|
@@ -21,7 +21,7 @@ try:
|
|
| 21 |
from fastapi import FastAPI, HTTPException
|
| 22 |
from fastapi.middleware.cors import CORSMiddleware
|
| 23 |
from pydantic import BaseModel, Field
|
| 24 |
-
import
|
| 25 |
FASTAPI_AVAILABLE = True
|
| 26 |
print("β
FastAPI available")
|
| 27 |
except ImportError as e:
|
|
@@ -201,9 +201,12 @@ if FASTAPI_AVAILABLE:
|
|
| 201 |
evaluation = await evaluate_action(request)
|
| 202 |
return evaluation
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
# ============== HUGGING FACE SPACES DETECTION ==============
|
| 209 |
def is_huggingface_spaces():
|
|
@@ -1162,22 +1165,20 @@ if __name__ == "__main__":
|
|
| 1162 |
print("π Environment:", "Hugging Face Spaces" if is_huggingface_spaces() else "Local Development")
|
| 1163 |
print("="*80)
|
| 1164 |
|
| 1165 |
-
#
|
| 1166 |
-
if FASTAPI_AVAILABLE:
|
| 1167 |
-
fastapi_thread = threading.Thread(target=run_fastapi, daemon=True)
|
| 1168 |
-
fastapi_thread.start()
|
| 1169 |
-
print("β
FastAPI server started on port 8000")
|
| 1170 |
-
print(" API endpoints available at:")
|
| 1171 |
-
print(" - GET /api/v1/config")
|
| 1172 |
-
print(" - POST /api/v1/evaluate")
|
| 1173 |
-
print(" - POST /api/v1/process")
|
| 1174 |
-
print(" - POST /api/v1/simulate")
|
| 1175 |
-
|
| 1176 |
-
# Create the demo
|
| 1177 |
demo = create_enhanced_demo()
|
| 1178 |
|
| 1179 |
-
#
|
| 1180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1181 |
server_name="0.0.0.0",
|
| 1182 |
server_port=7860,
|
| 1183 |
share=False,
|
|
|
|
| 21 |
from fastapi import FastAPI, HTTPException
|
| 22 |
from fastapi.middleware.cors import CORSMiddleware
|
| 23 |
from pydantic import BaseModel, Field
|
| 24 |
+
from gradio import mount_gradio_app
|
| 25 |
FASTAPI_AVAILABLE = True
|
| 26 |
print("β
FastAPI available")
|
| 27 |
except ImportError as e:
|
|
|
|
| 201 |
evaluation = await evaluate_action(request)
|
| 202 |
return evaluation
|
| 203 |
|
| 204 |
+
print("β
FastAPI endpoints configured")
|
| 205 |
+
print(" Endpoints will be available at:")
|
| 206 |
+
print(" - /api/v1/config")
|
| 207 |
+
print(" - /api/v1/evaluate")
|
| 208 |
+
print(" - /api/v1/process")
|
| 209 |
+
print(" - /api/v1/simulate")
|
| 210 |
|
| 211 |
# ============== HUGGING FACE SPACES DETECTION ==============
|
| 212 |
def is_huggingface_spaces():
|
|
|
|
| 1165 |
print("π Environment:", "Hugging Face Spaces" if is_huggingface_spaces() else "Local Development")
|
| 1166 |
print("="*80)
|
| 1167 |
|
| 1168 |
+
# Create the Gradio demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1169 |
demo = create_enhanced_demo()
|
| 1170 |
|
| 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,
|