MJobe commited on
Commit
0c14995
·
1 Parent(s): 5738ed4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -25
main.py CHANGED
@@ -9,31 +9,6 @@ from starlette.middleware.cors import CORSMiddleware
9
 
10
  app = FastAPI()
11
 
12
- ALLOWED_ORIGINS = [
13
- "http://localhost",
14
- "http://localhost:8080",
15
- "http://127.0.0.1:5500",
16
- "http://127.0.0.1:5500/DataExtractAI.html",
17
- ]
18
-
19
- # Handle CORS preflight requests
20
- @app.options('/{rest_of_path:path}')
21
- async def preflight_handler(request: Request, rest_of_path: str) -> Response:
22
- response = Response()
23
- response.headers['Access-Control-Allow-Origin'] = ', '.join(ALLOWED_ORIGINS)
24
- response.headers['Access-Control-Allow-Methods'] = 'POST, GET, DELETE, OPTIONS'
25
- response.headers['Access-Control-Allow-Headers'] = 'Authorization, Content-Type'
26
- return response
27
-
28
- # Set CORS headers
29
- @app.middleware("http")
30
- async def add_CORS_header(request: Request, call_next):
31
- response = await call_next(request)
32
- response.headers['Access-Control-Allow-Origin'] = ', '.join(ALLOWED_ORIGINS)
33
- response.headers['Access-Control-Allow-Methods'] = 'POST, GET, DELETE, OPTIONS'
34
- response.headers['Access-Control-Allow-Headers'] = 'Authorization, Content-Type'
35
- return response
36
-
37
  # Use a pipeline as a high-level helper
38
  nlp_qa = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
39
  # Use a pipeline as a high-level helper
@@ -153,3 +128,13 @@ async def perform_document_qa_jsonp(
153
  return JSONResponse(content=response_data, callback=callback)
154
  except Exception as e:
155
  return JSONResponse(content={"error": str(e)}, callback=callback)
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  app = FastAPI()
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Use a pipeline as a high-level helper
13
  nlp_qa = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
14
  # Use a pipeline as a high-level helper
 
128
  return JSONResponse(content=response_data, callback=callback)
129
  except Exception as e:
130
  return JSONResponse(content={"error": str(e)}, callback=callback)
131
+
132
+ # Set up CORS middleware
133
+ origins = ["*"] # or specify your list of allowed origins
134
+ app.add_middleware(
135
+ CORSMiddleware,
136
+ allow_origins=origins,
137
+ allow_credentials=True,
138
+ allow_methods=["*"],
139
+ allow_headers=["*"],
140
+ )