RanM commited on
Commit
80dd1f5
·
verified ·
1 Parent(s): 252ee3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  from fastapi import FastAPI, HTTPException
 
3
  from pydantic import BaseModel
4
  import spacy
5
  import re
@@ -11,6 +12,15 @@ os.environ['MPLCONFIGDIR'] = '/tmp/.matplotlib'
11
  # Initialize FastAPI app
12
  app = FastAPI()
13
 
 
 
 
 
 
 
 
 
 
14
  # Load the spaCy models once
15
  nlp = spacy.load("en_core_web_sm")
16
  nlp_coref = spacy.load("en_coreference_web_trf")
@@ -97,5 +107,5 @@ async def predict(coref_request: CorefRequest):
97
  raise HTTPException(status_code=400, detail="Coreference resolution failed")
98
 
99
  if __name__ == "__main__":
100
- port = int(os.environ.get("PORT", 7860))
101
- uvicorn.run(app, host="0.0.0.0", port=port)
 
1
  import os
2
  from fastapi import FastAPI, HTTPException
3
+ from fastapi.middleware.cors import CORSMiddleware
4
  from pydantic import BaseModel
5
  import spacy
6
  import re
 
12
  # Initialize FastAPI app
13
  app = FastAPI()
14
 
15
+ # Add CORS middleware
16
+ app.add_middleware(
17
+ CORSMiddleware,
18
+ allow_origins=["*"], # Adjust the origins as needed
19
+ allow_credentials=True,
20
+ allow_methods=["*"],
21
+ allow_headers=["*"],
22
+ )
23
+
24
  # Load the spaCy models once
25
  nlp = spacy.load("en_core_web_sm")
26
  nlp_coref = spacy.load("en_coreference_web_trf")
 
107
  raise HTTPException(status_code=400, detail="Coreference resolution failed")
108
 
109
  if __name__ == "__main__":
110
+ import uvicorn
111
+ uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860)))