added ai model settings

This commit is contained in:
2021-07-25 13:18:18 +10:00
parent 04fa819a9a
commit c6a31f24e5
2 changed files with 23 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
from wtforms import SubmitField, StringField, FloatField, HiddenField, validators, Form
from wtforms import SubmitField, StringField, FloatField, HiddenField, validators, Form, SelectField
from flask_wtf import FlaskForm
from flask import request, render_template, redirect
from main import db, app, ma
@@ -9,6 +9,17 @@ from flask_login import login_required, current_user
# pylint: disable=no-member
################################################################################
# Class describing AI_MODEL in the database, and via sqlalchemy, connected to the DB as well
################################################################################
class AI_Model(db.Model):
__tablename__ = "ai_model"
id = db.Column(db.Integer, primary_key=True )
name = db.Column(db.String)
def __repr__(self):
return f"<id: {self.id}, name: {self.name}>"
################################################################################
# Class describing Settings in the database, and via sqlalchemy, connected to the DB as well
################################################################################
@@ -17,6 +28,8 @@ class Settings(db.Model):
import_path = db.Column(db.String)
storage_path = db.Column(db.String)
recycle_bin_path = db.Column(db.String)
default_model = db.Column(db.Integer,db.ForeignKey('ai_model.id'), unique=True, nullable=False)
default_threshold = db.Column(db.Integer)
def __repr__(self):
return f"<id: {self.id}, import_path: {self.import_path}, storage_path: {self.storage_path}, recycle_bin_path: {self.recycle_bin_path}>"
@@ -40,6 +53,8 @@ class SettingsForm(FlaskForm):
import_path = StringField('Path(s) to import from:', [validators.DataRequired()])
storage_path = StringField('Path to store sorted images to:', [validators.DataRequired()])
recycle_bin_path = StringField('Path to temporarily store deleted images in:', [validators.DataRequired()])
default_model = SelectField( 'default_model', choices=[(c.id, c.name) for c in AI_Model.query.order_by('id')] )
default_threshold = StringField('Face Distance threshold (below is a match):', [validators.DataRequired()])
submit = SubmitField('Save' )
################################################################################
@@ -62,6 +77,8 @@ def settings():
s.import_path = request.form['import_path']
s.storage_path = request.form['storage_path']
s.recycle_bin_path = request.form['recycle_bin_path']
s.default_model = request.form['default_model']
s.default_threshold = request.form['default_threshold']
db.session.commit()
return redirect( '/settings' )
except SQLAlchemyError as e:

View File

@@ -9,7 +9,11 @@
{% elif field.type != 'SubmitField' %}
<div class="input-group">
{{ field.label( class="input-group-text col-3 justify-content-end" ) }}
{{ field( class="form-control col-9" ) }}
{% if field.type == 'SelectField' %}
{{ field( class="form-select col-9" ) }}
{% else %}
{{ field( class="form-control col-9" ) }}
{% endif %}
</div class="">
{% endif %}
{% endfor %}