Spaces:
Paused
Paused
add file
Browse files
main.py
CHANGED
|
@@ -6,6 +6,30 @@ from rapidocr_onnxruntime import RapidOCR
|
|
| 6 |
# det_model_path同理
|
| 7 |
model = RapidOCR()
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
@app.get("/")
|
| 10 |
def read_root():
|
| 11 |
return {"Hello": "World!"}
|
|
|
|
| 6 |
# det_model_path同理
|
| 7 |
model = RapidOCR()
|
| 8 |
|
| 9 |
+
|
| 10 |
+
# 1、导入对应的包
|
| 11 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
+
|
| 13 |
+
app = FastAPI()
|
| 14 |
+
|
| 15 |
+
# 2、声明一个 源 列表;重点:要包含跨域的客户端 源
|
| 16 |
+
origins = [
|
| 17 |
+
"https://hycjack-fastapi-rapidocr.hf.space/",
|
| 18 |
+
"http://localhost",
|
| 19 |
+
"http://localhost:7860",
|
| 20 |
+
# 客户端的源
|
| 21 |
+
"http://127.0.0.1:7860"
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
# 3、配置 CORSMiddleware
|
| 25 |
+
app.add_middleware(
|
| 26 |
+
CORSMiddleware,
|
| 27 |
+
allow_origins=origins, # 允许访问的源
|
| 28 |
+
allow_credentials=True, # 支持 cookie
|
| 29 |
+
allow_methods=["*"], # 允许使用的请求方法
|
| 30 |
+
allow_headers=["*"] # 允许携带的 Headers
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
@app.get("/")
|
| 34 |
def read_root():
|
| 35 |
return {"Hello": "World!"}
|