SentimentsFaces/main.py

38 lines
1.0 KiB
Python

from deepface import DeepFace
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Optional
# objs = DeepFace.analyze(img_path = "data/1.jpg",
# actions = ['age', 'gender', 'race', 'emotion']
# )
# print(objs)
# objs = DeepFace.analyze(img_path = "data/2.jpg",
# actions = ['age', 'gender', 'race', 'emotion']
# )
# print(objs)
# objs = DeepFace.analyze(img_path = "data/3.jpg",
# actions = ['age', 'gender', 'race', 'emotion']
# )
# print(objs)
# objs = DeepFace.analyze(img_path = "data/4.jpg",
# actions = ['age', 'gender', 'race', 'emotion']
# )
# print(objs)
# print(objs)
class Response(BaseModel):
path: str
actions : Optional[list] = ['age', 'gender', 'race', 'emotion']
app = FastAPI()
@app.get("/")
def read_main():
return {"message": "This is your main app"}
@app.post("/faces/")
def calculate_api(response: Response):
path = response.path
actions = response.actions
objs = DeepFace.analyze(img_path =path,
actions = actions)
return objs