first pass of allowing to scan for all files in import and storage paths <- works, and showing all unknown faces to handle them somehow - very rudimentary
This commit is contained in:
63
ai.py
63
ai.py
@@ -5,9 +5,14 @@ from main import db, app, ma
|
||||
from sqlalchemy import Sequence
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from status import st, Status
|
||||
from files import Entry, File
|
||||
from path import Path, PathType
|
||||
from files import Entry, Dir, File, PathDirLink
|
||||
from person import Refimg, Person, PersonRefimgLink
|
||||
from flask_login import login_required, current_user
|
||||
from PIL import Image
|
||||
import io
|
||||
import base64
|
||||
import json
|
||||
|
||||
from job import Job, JobExtra, Joblog, NewJob
|
||||
from face import Face, FaceFileLink, FaceRefimgLink
|
||||
@@ -52,3 +57,59 @@ def run_ai_on():
|
||||
job=NewJob( "run_ai_on", 0, None, jex )
|
||||
st.SetMessage( f"Created <a href=/job/{job.id}>Job #{job.id}</a> to Look for face(s) in selected file(s)")
|
||||
return render_template("base.html")
|
||||
|
||||
@app.route("/run_ai_on_import")
|
||||
@login_required
|
||||
def run_ai_on_import():
|
||||
jex=[]
|
||||
jex.append( JobExtra( name=f"person", value="all" ) )
|
||||
paths=Path.query.join(PathType).filter(PathType.name=='Import').all()
|
||||
path_cnt=0
|
||||
for p in paths:
|
||||
d = Dir.query.join(PathDirLink).filter(PathDirLink.path_id==p.id).filter(Dir.rel_path=='').first()
|
||||
jex.append( JobExtra( name=f"eid-{path_cnt}", value=f"{d.eid}" ) )
|
||||
path_cnt+=1
|
||||
print(jex)
|
||||
job=NewJob( "run_ai_on", 0, None, jex )
|
||||
st.SetMessage( f"Created <a href=/job/{job.id}>Job #{job.id}</a> to Look for face(s) in import path(s)")
|
||||
return render_template("base.html")
|
||||
|
||||
@app.route("/run_ai_on_storage")
|
||||
@login_required
|
||||
def run_ai_on_storage():
|
||||
jex=[]
|
||||
jex.append( JobExtra( name=f"person", value="all" ) )
|
||||
paths=Path.query.join(PathType).filter(PathType.name=='Storage').all()
|
||||
path_cnt=0
|
||||
for p in paths:
|
||||
d = Dir.query.join(PathDirLink).filter(PathDirLink.path_id==p.id).filter(Dir.rel_path=='').first()
|
||||
jex.append( JobExtra( name=f"eid-{path_cnt}", value=f"{d.eid}" ) )
|
||||
path_cnt+=1
|
||||
print(jex)
|
||||
job=NewJob( "run_ai_on", 0, None, jex )
|
||||
st.SetMessage( f"Created <a href=/job/{job.id}>Job #{job.id}</a> to Look for face(s) in storage path(s)")
|
||||
return render_template("base.html")
|
||||
|
||||
@app.route("/unmatched_faces")
|
||||
@login_required
|
||||
def unmatched_faces():
|
||||
faces=Face.query.join(FaceFileLink).join(FaceRefimgLink, isouter=True).filter(FaceRefimgLink.refimg_id==None).limit(10).all()
|
||||
imgs={}
|
||||
for face in faces:
|
||||
face.locn=json.loads("["+face.locn+"]")
|
||||
f = Entry.query.join(File).join(FaceFileLink).filter(FaceFileLink.face_id==face.id).first()
|
||||
face.file_eid=f.id
|
||||
face.url=f.FullPathOnFS()
|
||||
x=face.locn[0][3]*0.95
|
||||
y=face.locn[0][0]*0.95
|
||||
x2=face.locn[0][1]*1.05
|
||||
y2=face.locn[0][2]*1.05
|
||||
im = Image.open(f.FullPathOnFS())
|
||||
region = im.crop((x, y, x2, y2))
|
||||
img_bytearray = io.BytesIO()
|
||||
region.save(img_bytearray, format='JPEG')
|
||||
img_bytearray = img_bytearray.getvalue()
|
||||
face.img = base64.b64encode(img_bytearray)
|
||||
face.img = str(face.img)[2:-1]
|
||||
|
||||
return render_template("faces.html", faces=faces)
|
||||
|
||||
Reference in New Issue
Block a user