Spaces:
Runtime error
Runtime error
Oleg Lavrovsky
commited on
CORS support
Browse files
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"""
|