示例#1
0
 def post_save(cls, sender, document, **kwargs):
     globals.add_to_embeddings(username= document.user_name, encoding=pickle.loads(document.encoding))
示例#2
0
app = FastAPI()

origins = [globals.CORS_ORIGIN]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

global_init()
for user in UserModel.objects:
    globals.add_to_embeddings(username=user.user_name,
                              encoding=pickle.loads(user.encoding))


@app.post("/register/")
def register(file: UploadFile = File(...), user_name: str = Form(...)):
    try:
        UserModel.objects.get(user_name=user_name)
        print("############USER ALREADY EXISTS ################")
        return False
    except UserModel.DoesNotExist:
        """If user_name not in db than error will be handled here """
        user_model_obj = UserModel()
        file_name = _save(file)
        img = Image.open(file_name)
        width, height = img.size
        print(width, height)