nikajoon commited on
Commit
0a4ccdb
1 Parent(s): 8dc776e

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +37 -19
api.py CHANGED
@@ -1,19 +1,37 @@
1
- from fastapi import FastAPI
2
- from fastapi.responses import HTMLResponse
3
-
4
- app = FastAPI()
5
-
6
- @app.get("/", response_class=HTMLResponse)
7
- async def read_root():
8
- html_content = """
9
- <html>
10
- <head>
11
- <title>My FastAPI App</title>
12
- </head>
13
- <body>
14
- <h1>Hello from FastAPI!</h1>
15
- <p>This is a sample application running on Hugging Face Spaces.</p>
16
- </body>
17
- </html>
18
- """
19
- return html_content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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