Spaces:
Running
Running
Update blaxel_main.py
Browse files- blaxel_main.py +18 -2
blaxel_main.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
-
# blaxel_main.py (Smoke Test)
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from sse_starlette.sse import EventSourceResponse
|
| 5 |
import asyncio
|
|
|
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
@@ -23,4 +25,18 @@ async def solve_problem(request: ProblemRequest):
|
|
| 23 |
await asyncio.sleep(0.5)
|
| 24 |
yield "Test complete. The connection is good!"
|
| 25 |
|
| 26 |
-
return EventSourceResponse(stream_test())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# blaxel_main.py (Smoke Test - Now with Blaxel-specific ports)
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from sse_starlette.sse import EventSourceResponse
|
| 5 |
import asyncio
|
| 6 |
+
import os # <-- 1. Import os
|
| 7 |
+
import uvicorn # <-- 2. Import uvicorn
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 25 |
await asyncio.sleep(0.5)
|
| 26 |
yield "Test complete. The connection is good!"
|
| 27 |
|
| 28 |
+
return EventSourceResponse(stream_test())
|
| 29 |
+
|
| 30 |
+
# --- 3. This is the new, critical part ---
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
# Blaxel provides the host and port through environment variables
|
| 33 |
+
# We must use these.
|
| 34 |
+
HOST = os.getenv("BL_SERVER_HOST", "0.0.0.0")
|
| 35 |
+
|
| 36 |
+
# We use 'int()' to convert the port from a string to a number
|
| 37 |
+
# Use 8080 as a fallback for local testing
|
| 38 |
+
PORT = int(os.getenv("BL_SERVER_PORT", "8080"))
|
| 39 |
+
|
| 40 |
+
# This line replaces the "Start Command" you were looking for.
|
| 41 |
+
# It tells our app how to run.
|
| 42 |
+
uvicorn.run(app, host=HOST, port=PORT)
|