Spaces:
Sleeping
Sleeping
Update api/server.py
Browse files- api/server.py +27 -0
api/server.py
CHANGED
|
@@ -210,6 +210,33 @@ os.environ.update({
|
|
| 210 |
"TORCH_HOME": str(HF_CACHE_DIR),
|
| 211 |
"HOME": str(HF_CACHE_DIR)
|
| 212 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
import os.path
|
| 214 |
if not hasattr(os.path, "expanduser_original"):
|
| 215 |
os.path.expanduser_original = os.path.expanduser
|
|
|
|
| 210 |
"TORCH_HOME": str(HF_CACHE_DIR),
|
| 211 |
"HOME": str(HF_CACHE_DIR)
|
| 212 |
})
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
from fastapi import FastAPI, BackgroundTasks
|
| 216 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 217 |
+
|
| 218 |
+
app = FastAPI(title="AdMaker API")
|
| 219 |
+
|
| 220 |
+
# Allow frontend access
|
| 221 |
+
app.add_middleware(
|
| 222 |
+
CORSMiddleware,
|
| 223 |
+
allow_origins=["*"], # or restrict to your domain
|
| 224 |
+
allow_credentials=True,
|
| 225 |
+
allow_methods=["*"],
|
| 226 |
+
allow_headers=["*"],
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
# Example routes
|
| 230 |
+
@app.get("/")
|
| 231 |
+
def root():
|
| 232 |
+
return {"message": "AdMaker backend running!"}
|
| 233 |
+
|
| 234 |
+
@app.get("/health")
|
| 235 |
+
def health_check():
|
| 236 |
+
return {"status": "ok"}
|
| 237 |
+
|
| 238 |
+
# (Optional) Add your /submit_idea, /status/{task_id}, etc. here
|
| 239 |
+
|
| 240 |
import os.path
|
| 241 |
if not hasattr(os.path, "expanduser_original"):
|
| 242 |
os.path.expanduser_original = os.path.expanduser
|