merge
This commit is contained in:
10
README.md
10
README.md
@@ -10,6 +10,7 @@ Setup:
|
|||||||
```
|
```
|
||||||
{
|
{
|
||||||
"title": "My Labeler",
|
"title": "My Labeler",
|
||||||
|
"images": "global",
|
||||||
"users": [
|
"users": [
|
||||||
"user1",
|
"user1",
|
||||||
"name2"
|
"name2"
|
||||||
@@ -66,6 +67,15 @@ Setup:
|
|||||||
- Start the docker instance
|
- Start the docker instance
|
||||||
- Open the URL in http://localhost:$EXPOSE
|
- Open the URL in http://localhost:$EXPOSE
|
||||||
|
|
||||||
|
## Config entries
|
||||||
|
|
||||||
|
- title: Name of the site
|
||||||
|
- images:
|
||||||
|
- global: Every labeler sees all images in folder data/images/
|
||||||
|
- personal: Labeler only sees images under folder data/images/[LabelerName]/
|
||||||
|
- users: List of labeler names
|
||||||
|
- labels: List of labels, see below
|
||||||
|
|
||||||
## Label types
|
## Label types
|
||||||
|
|
||||||
Label entries require "type" and "name". All labels can include
|
Label entries require "type" and "name". All labels can include
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from flask import (
|
|||||||
from revprox import ReverseProxied
|
from revprox import ReverseProxied
|
||||||
|
|
||||||
# configuration
|
# configuration
|
||||||
VERSION = "2022.05.27"
|
VERSION = "2022.06.14"
|
||||||
IMAGEDIR = "/data/images/"
|
IMAGEDIR = "/data/images/"
|
||||||
LABELDIR = "/data/labels/"
|
LABELDIR = "/data/labels/"
|
||||||
CONFIG_FILE = "/data/config.json"
|
CONFIG_FILE = "/data/config.json"
|
||||||
@@ -32,37 +32,37 @@ app.config.from_object(__name__)
|
|||||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||||
|
|
||||||
|
|
||||||
@app.before_request
|
def read_config():
|
||||||
def before_request_func():
|
|
||||||
g.version = app.config["VERSION"]
|
|
||||||
try:
|
try:
|
||||||
with open(app.config["CONFIG_FILE"], "rt") as fp:
|
with open(app.config["CONFIG_FILE"], "rt") as fp:
|
||||||
g.config = json.load(fp)
|
config = json.load(fp)
|
||||||
g.labels = g.config["labels"]
|
|
||||||
g.users = g.config["users"]
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning(e)
|
logging.warning(e)
|
||||||
logging.warning("config.json could not be read. using defaults.")
|
logging.warning("config.json could not be read. using defaults.")
|
||||||
g.labels = [
|
config = {
|
||||||
{"type": "checkbox", "name": "my_check", "default": "off"},
|
"title": "Labeler",
|
||||||
{"type": "text", "name": "my_text", "default": "Some text"},
|
"labels": [
|
||||||
{
|
{"type": "checkbox", "name": "my_check", "default": "off"},
|
||||||
"type": "range",
|
{"type": "text", "name": "my_text", "default": "Some text"},
|
||||||
"name": "my_slider",
|
{
|
||||||
"default": "75",
|
"type": "range",
|
||||||
"min": "0",
|
"name": "my_slider",
|
||||||
"max": "100",
|
"default": "75",
|
||||||
},
|
"min": "0",
|
||||||
]
|
"max": "100",
|
||||||
g.config = {"title": "Labeler", "labels": g.labels}
|
},
|
||||||
g.users = ["user"]
|
],
|
||||||
|
"users": "user",
|
||||||
|
}
|
||||||
|
|
||||||
if not "title" in g.config:
|
if not "title" in config:
|
||||||
g.config["title"] = "Labeler"
|
config["title"] = "Labeler"
|
||||||
if not "title" in g.config:
|
if not "images" in config:
|
||||||
g.config["title"] = "Labeler"
|
config["images"] = "global"
|
||||||
|
if not config["images"] in ("global", "personal"):
|
||||||
|
raise ValueError("Config 'images' is not global / personal")
|
||||||
|
|
||||||
for label in g.labels:
|
for label in config["labels"]:
|
||||||
if label["type"] == "range":
|
if label["type"] == "range":
|
||||||
label["value"] = label.get("default", label.get("min", ""))
|
label["value"] = label.get("default", label.get("min", ""))
|
||||||
elif label["type"] == "info":
|
elif label["type"] == "info":
|
||||||
@@ -70,6 +70,18 @@ def before_request_func():
|
|||||||
label["value"] = ""
|
label["value"] = ""
|
||||||
else:
|
else:
|
||||||
label["value"] = label.get("default", "")
|
label["value"] = label.get("default", "")
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
app.config["user_config"] = read_config()
|
||||||
|
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def before_request_func():
|
||||||
|
g.version = app.config["VERSION"]
|
||||||
|
g.config = app.config["user_config"]
|
||||||
|
g.labels = app.config["user_config"]["labels"]
|
||||||
|
g.users = app.config["user_config"]["users"]
|
||||||
|
|
||||||
|
|
||||||
def natural_key(string_):
|
def natural_key(string_):
|
||||||
@@ -92,10 +104,14 @@ def get_current_image(images):
|
|||||||
|
|
||||||
|
|
||||||
def get_image_list():
|
def get_image_list():
|
||||||
|
if g.config["images"] == "global":
|
||||||
|
image_path = app.config["IMAGEDIR"]
|
||||||
|
if g.config["images"] == "personal":
|
||||||
|
image_path = os.path.join(app.config["IMAGEDIR"], get_user())
|
||||||
image_list = sorted(
|
image_list = sorted(
|
||||||
[
|
[
|
||||||
os.path.join(app.config["IMAGEDIR"], x)
|
os.path.join(image_path, x)
|
||||||
for x in os.listdir(app.config["IMAGEDIR"])
|
for x in os.listdir(image_path)
|
||||||
if not x.endswith("json")
|
if not x.endswith("json")
|
||||||
],
|
],
|
||||||
key=natural_key,
|
key=natural_key,
|
||||||
@@ -129,24 +145,20 @@ def get_metadata(imagepath):
|
|||||||
|
|
||||||
|
|
||||||
def set_metadata(values, imagepath):
|
def set_metadata(values, imagepath):
|
||||||
|
"""Write metadata as json"""
|
||||||
metadata = [x.copy() for x in g.labels.copy() if x['type'] != "info"]
|
metadata = [x.copy() for x in g.labels.copy() if x["type"] != "info"]
|
||||||
for label in metadata:
|
for label in metadata:
|
||||||
if not "name" in label:
|
if not "name" in label:
|
||||||
continue
|
continue
|
||||||
if not label["name"] in values:
|
if not label["name"] in values:
|
||||||
values[label["name"]] = label.get("default", "")
|
values[label["name"]] = label.get("default", "")
|
||||||
|
|
||||||
# logging.warning((path, values))
|
|
||||||
if not os.path.exists(
|
|
||||||
os.path.join(app.config["IMAGEDIR"], os.path.basename(imagepath))
|
|
||||||
):
|
|
||||||
return
|
|
||||||
with open(get_metadata_path(imagepath), "wt") as fp:
|
with open(get_metadata_path(imagepath), "wt") as fp:
|
||||||
return json.dump(values, fp, indent=2, sort_keys=True)
|
return json.dump(values, fp, indent=2, sort_keys=True)
|
||||||
|
|
||||||
|
|
||||||
def set_user(user_name):
|
def set_user(user_name):
|
||||||
|
"""Set user in session, create dir for user labels"""
|
||||||
if user_name not in g.users:
|
if user_name not in g.users:
|
||||||
raise ValueError("No such user {}".format(user_name))
|
raise ValueError("No such user {}".format(user_name))
|
||||||
session["user"] = user_name
|
session["user"] = user_name
|
||||||
|
|||||||
Reference in New Issue
Block a user