Spaces:
Running
Running
Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile, Form, Request
|
2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
from fastapi.responses import HTMLResponse, JSONResponse, FileResponse
|
4 |
+
from fastapi.staticfiles import StaticFiles
|
5 |
+
from fastapi.templating import Jinja2Templates
|
6 |
+
import shutil, os
|
7 |
+
from tempfile import gettempdir
|
8 |
+
|
9 |
+
app = FastAPI()
|
10 |
+
|
11 |
+
# β
CORS to allow frontend access
|
12 |
+
app.add_middleware(
|
13 |
+
CORSMiddleware,
|
14 |
+
allow_origins=["*"],
|
15 |
+
allow_credentials=True,
|
16 |
+
allow_methods=["*"],
|
17 |
+
allow_headers=["*"],
|
18 |
+
)
|
19 |
+
|
20 |
+
# β
Static assets
|
21 |
+
app.mount("/resources", StaticFiles(directory="resources"), name="resources")
|
22 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
23 |
+
|
24 |
+
# β
Jinja2 Templates
|
25 |
+
templates = Jinja2Templates(directory="templates")
|
26 |
+
|
27 |
+
# β
Serve Homepage
|
28 |
+
@app.get("/", response_class=HTMLResponse)
|
29 |
+
async def serve_home(request: Request):
|
30 |
+
return templates.TemplateResponse("homeS.html", {"request": request})
|