services/YOLO/Dockerfiles/app/app/app.py

33 lines
1.1 KiB
Python

# app/__init__.py
from flask import Flask
import requests
import json
import sys
import shutil
def create_app():
app = Flask(__name__)
@app.route('/create/<string:id>/')
def create(id):
import detect
import create_csv
attributes = ['Smiling', 'Bald', 'Bangs', 'Black_Hair', 'Blond_Hair', 'Brown_Hair', 'Chubby',
'Eyeglasses', 'Heavy_Makeup', 'Male', 'Mustache', 'No_Beard', 'Pale_Skin',
'Straight_Hair', 'Wavy_Hair', 'Wearing_Earrings', 'Wearing_Hat', 'Wearing_Necklace',
'Wearing_Lipstick', 'Young']
filename = id+'.png'
in_path = "/Datasets/grids/"+filename #PATH TO VOLUME
out_path = './images/'+filename
weight_path="runs/train/exp4/weights/last.pt"
#r = requests.get("http://127.0.0.1:50011/update/"+id+"/"+attr+"/"+str(value)+"/")
#print("Message",file=sys.stdout)
shutil.copy(in_path,out_path)
detect.run(source=out_path,weights=weight_path,name=id,save_txt=True)
file_yolo="./runs/detect/"+id+"/labels/"+id+".txt"
file_csv="/Datasets/database/"+id+".csv"
create_csv.create_csv(file_yolo,file_csv,attributes)
return str(5)
return app