Spaces:
Sleeping
Sleeping
Update api.py
Browse files
api.py
CHANGED
@@ -1,19 +1,37 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
-
from fastapi.responses import HTMLResponse
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
# تنظیمات CORS
|
8 |
+
origins = [
|
9 |
+
"http://localhost",
|
10 |
+
"http://localhost:8000",
|
11 |
+
"http://localhost:7860",
|
12 |
+
"https://nikajoon-test1.hf.space",
|
13 |
+
# "http://yourdomain.com", # دامنه سایت شما
|
14 |
+
]
|
15 |
+
|
16 |
+
app.add_middleware(
|
17 |
+
CORSMiddleware,
|
18 |
+
allow_origins=origins,
|
19 |
+
allow_credentials=True,
|
20 |
+
allow_methods=["*"],
|
21 |
+
allow_headers=["*"],
|
22 |
+
)
|
23 |
+
|
24 |
+
@app.get("/", response_class=HTMLResponse)
|
25 |
+
async def read_root():
|
26 |
+
html_content = """
|
27 |
+
<html>
|
28 |
+
<head>
|
29 |
+
<title>My FastAPI App</title>
|
30 |
+
</head>
|
31 |
+
<body>
|
32 |
+
<h1>Hello from FastAPI!</h1>
|
33 |
+
<p>This is a sample application running on Hugging Face Spaces.</p>
|
34 |
+
</body>
|
35 |
+
</html>
|
36 |
+
"""
|
37 |
+
return html_content
|