Spaces:
Sleeping
Sleeping
tesst
Browse files- app/main.py +27 -3
- app/templates/index.html +2 -2
app/main.py
CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI, Request
|
|
2 |
from fastapi.templating import Jinja2Templates
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
from fastapi.responses import JSONResponse, FileResponse
|
|
|
5 |
from optimum.neuron import utils
|
6 |
import logging
|
7 |
import sys
|
@@ -19,6 +20,15 @@ logger = logging.getLogger(__name__)
|
|
19 |
|
20 |
app = FastAPI()
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Get the absolute path to the static directory
|
23 |
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
|
24 |
logger.info(f"Static directory path: {static_dir}")
|
@@ -39,7 +49,15 @@ async def health_check():
|
|
39 |
@app.get("/")
|
40 |
async def home(request: Request):
|
41 |
logger.info("Home page requested")
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
@app.get("/api/models")
|
45 |
async def get_model_list():
|
@@ -95,9 +113,15 @@ async def get_model_info_endpoint(model_id: str):
|
|
95 |
)
|
96 |
|
97 |
@app.get("/static/{path:path}")
|
98 |
-
async def static_files(path: str):
|
99 |
logger.info(f"Static file requested: {path}")
|
100 |
file_path = os.path.join(static_dir, path)
|
101 |
if os.path.exists(file_path):
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
return JSONResponse(status_code=404, content={"error": "File not found"})
|
|
|
2 |
from fastapi.templating import Jinja2Templates
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
from fastapi.responses import JSONResponse, FileResponse
|
5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
6 |
from optimum.neuron import utils
|
7 |
import logging
|
8 |
import sys
|
|
|
20 |
|
21 |
app = FastAPI()
|
22 |
|
23 |
+
# Add CORS middleware
|
24 |
+
app.add_middleware(
|
25 |
+
CORSMiddleware,
|
26 |
+
allow_origins=["*"],
|
27 |
+
allow_credentials=True,
|
28 |
+
allow_methods=["*"],
|
29 |
+
allow_headers=["*"],
|
30 |
+
)
|
31 |
+
|
32 |
# Get the absolute path to the static directory
|
33 |
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
|
34 |
logger.info(f"Static directory path: {static_dir}")
|
|
|
49 |
@app.get("/")
|
50 |
async def home(request: Request):
|
51 |
logger.info("Home page requested")
|
52 |
+
# Get the base URL with proper protocol
|
53 |
+
base_url = str(request.base_url).replace("http://", "https://")
|
54 |
+
return templates.TemplateResponse(
|
55 |
+
"index.html",
|
56 |
+
{
|
57 |
+
"request": request,
|
58 |
+
"base_url": base_url
|
59 |
+
}
|
60 |
+
)
|
61 |
|
62 |
@app.get("/api/models")
|
63 |
async def get_model_list():
|
|
|
113 |
)
|
114 |
|
115 |
@app.get("/static/{path:path}")
|
116 |
+
async def static_files(path: str, request: Request):
|
117 |
logger.info(f"Static file requested: {path}")
|
118 |
file_path = os.path.join(static_dir, path)
|
119 |
if os.path.exists(file_path):
|
120 |
+
response = FileResponse(file_path)
|
121 |
+
# Ensure proper content type
|
122 |
+
if path.endswith('.css'):
|
123 |
+
response.headers["content-type"] = "text/css"
|
124 |
+
elif path.endswith('.js'):
|
125 |
+
response.headers["content-type"] = "application/javascript"
|
126 |
+
return response
|
127 |
return JSONResponse(status_code=404, content={"error": "File not found"})
|
app/templates/index.html
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Model Configuration Explorer</title>
|
7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
8 |
-
<link rel="stylesheet" href="{{
|
9 |
</head>
|
10 |
<body>
|
11 |
<div class="container">
|
@@ -60,6 +60,6 @@
|
|
60 |
</section>
|
61 |
</div>
|
62 |
|
63 |
-
<script src="{{
|
64 |
</body>
|
65 |
</html>
|
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Model Configuration Explorer</title>
|
7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
8 |
+
<link rel="stylesheet" href="{{ base_url }}static/css/styles.css">
|
9 |
</head>
|
10 |
<body>
|
11 |
<div class="container">
|
|
|
60 |
</section>
|
61 |
</div>
|
62 |
|
63 |
+
<script src="{{ base_url }}static/js/main.js"></script>
|
64 |
</body>
|
65 |
</html>
|