Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# app.py
|
| 2 |
from fastapi import FastAPI, HTTPException, Request
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
import os, json
|
|
@@ -7,6 +6,7 @@ app = FastAPI()
|
|
| 7 |
PROJECTS_DIR = "projects"
|
| 8 |
os.makedirs(PROJECTS_DIR, exist_ok=True)
|
| 9 |
|
|
|
|
| 10 |
@app.get("/load")
|
| 11 |
def load_project(project: str):
|
| 12 |
"""
|
|
@@ -20,6 +20,7 @@ def load_project(project: str):
|
|
| 20 |
data = json.load(f)
|
| 21 |
return JSONResponse(content=data)
|
| 22 |
|
|
|
|
| 23 |
@app.post("/save")
|
| 24 |
async def save_project(project: str, request: Request):
|
| 25 |
"""
|
|
@@ -32,3 +33,9 @@ async def save_project(project: str, request: Request):
|
|
| 32 |
with open(path, "w", encoding="utf-8") as f:
|
| 33 |
json.dump(body, f, indent=2)
|
| 34 |
return JSONResponse(content={"success": True})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException, Request
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
import os, json
|
|
|
|
| 6 |
PROJECTS_DIR = "projects"
|
| 7 |
os.makedirs(PROJECTS_DIR, exist_ok=True)
|
| 8 |
|
| 9 |
+
|
| 10 |
@app.get("/load")
|
| 11 |
def load_project(project: str):
|
| 12 |
"""
|
|
|
|
| 20 |
data = json.load(f)
|
| 21 |
return JSONResponse(content=data)
|
| 22 |
|
| 23 |
+
|
| 24 |
@app.post("/save")
|
| 25 |
async def save_project(project: str, request: Request):
|
| 26 |
"""
|
|
|
|
| 33 |
with open(path, "w", encoding="utf-8") as f:
|
| 34 |
json.dump(body, f, indent=2)
|
| 35 |
return JSONResponse(content={"success": True})
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
# When you run `python app.py`, this will start Uvicorn on the HF Spaces port.
|
| 40 |
+
import uvicorn
|
| 41 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|