Commit
·
b1ef674
1
Parent(s):
3d09ea6
Add CORS config
Browse files
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
# from flask import Flask, request, jsonify, render_template, make_response
|
| 2 |
# from flask_cors import CORS
|
|
|
|
|
|
|
| 3 |
import uvicorn
|
| 4 |
import logging
|
| 5 |
-
from fastapi import FastAPI, File, UploadFile, Form, Response
|
| 6 |
import numpy as np
|
| 7 |
import cv2
|
| 8 |
|
|
@@ -14,6 +15,20 @@ from src.utils import cv_to_pil, pil_to_cv
|
|
| 14 |
app = FastAPI()
|
| 15 |
logger = logging.getLogger('uvicorn')
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def to_byte_response(img):
|
| 19 |
return cv2.imencode('.png', img)[1].tobytes()
|
|
|
|
| 1 |
# from flask import Flask, request, jsonify, render_template, make_response
|
| 2 |
# from flask_cors import CORS
|
| 3 |
+
from fastapi import FastAPI, File, UploadFile, Form, Response
|
| 4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
import uvicorn
|
| 6 |
import logging
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
import cv2
|
| 9 |
|
|
|
|
| 15 |
app = FastAPI()
|
| 16 |
logger = logging.getLogger('uvicorn')
|
| 17 |
|
| 18 |
+
origins = [
|
| 19 |
+
"http://localhost",
|
| 20 |
+
"http://localhost:8081",
|
| 21 |
+
"https://digitalnaturegroup.github.io/critique-computational-alternative-process",
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
app.add_middleware(
|
| 25 |
+
CORSMiddleware,
|
| 26 |
+
allow_origins=origins,
|
| 27 |
+
allow_credentials=True,
|
| 28 |
+
allow_methods=["*"],
|
| 29 |
+
allow_headers=["*"],
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
|
| 33 |
def to_byte_response(img):
|
| 34 |
return cv2.imencode('.png', img)[1].tobytes()
|