Oleg Lavrovsky commited on
Commit
4f97961
·
unverified ·
1 Parent(s): 789ec24

CORS support

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from contextlib import asynccontextmanager
2
  from fastapi import FastAPI, HTTPException
 
3
  from pydantic import BaseModel
4
 
5
  from torch import cuda
@@ -61,6 +62,14 @@ app = FastAPI(
61
  lifespan=lifespan
62
  )
63
 
 
 
 
 
 
 
 
 
64
  @app.get("/predict", response_model=ModelResponse)
65
  async def predict(q: str):
66
  """Generate a model response for input text"""
 
1
  from contextlib import asynccontextmanager
2
  from fastapi import FastAPI, HTTPException
3
+ from fastapi.middleware.cors import CORSMiddleware
4
  from pydantic import BaseModel
5
 
6
  from torch import cuda
 
62
  lifespan=lifespan
63
  )
64
 
65
+ app.add_middleware(
66
+ CORSMiddleware,
67
+ allow_origins=["*"],
68
+ allow_credentials=True,
69
+ allow_methods=["*"],
70
+ allow_headers=["*"],
71
+ )
72
+
73
  @app.get("/predict", response_model=ModelResponse)
74
  async def predict(q: str):
75
  """Generate a model response for input text"""