annotation tools for making the iterations publication (Manetta & Jara) - https://iterations.space/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

150 lines
4.3 KiB

#!/usr/bin/env python3
import sys, os
import flask
from flask import request, redirect, url_for
from werkzeug.utils import secure_filename
from functions import *
import readings
import tfidf
from flaskext.markdown import Markdown
# Upload settings
UPLOAD_FOLDER_TRACES = 'static/visual-traces/'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
# Create the application.
APP = flask.Flask(__name__)
APP.config['UPLOAD_FOLDER_TRACES'] = UPLOAD_FOLDER_TRACES
Markdown(APP)
tools = [
"curves",
"color",
"text",
"visual-traces"
]
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@APP.route('/', methods=['GET'])
def index():
return flask.render_template('index.html', tools=tools)
@APP.route('/text/', methods=['GET', 'POST'])
def text():
marker = request.args.get('marker', '').strip()
markertype = request.args.get('marker-type', '').strip()
db, x = load_db('text.json')
markers = [db[x]['marker'] for x in db.keys()]
if marker:
if marker not in markers:
x = str(x + 1)
db[x] = {}
db[x]['marker'] = marker
db[x]['type'] = markertype
# write_db('text.json', db)
markers.append(marker)
for i in range(1, int(x)):
# description = request.args.get('description-{}'.format(i), '').strip()
description = request.args.get('description-1', '').strip()
db[str(i)]['description'] = description
write_db('text.json', db)
return flask.render_template('text.html', tools=tools, tool='text', db=db)
@APP.route('/color/', methods=['GET', 'POST'])
def color():
color = request.args.get('color', '').strip()
db, x = load_db('colors.json')
colors = [db[x]['color'] for x in db.keys()]
if color:
if color not in colors:
x = str(x + 1)
db[x] = {}
db[x]['color'] = color
write_db('colors.json', db)
colors.append(color)
return flask.render_template('color.html', tools=tools, tool='color',db=db)
@APP.route('/curves/', methods=['GET', 'POST'])
def curves():
curve = request.args.get('curve', '').strip()
db, x = load_db('curves.json')
curves = [db[x]['curve'] for x in db.keys()]
if curve:
if curve not in curves:
x = str(x + 1)
filename = '{}.svg'.format(x)
db[x] = {}
db[x]['curve'] = curve
db[x]['filename'] = filename
write_db('curves.json', db)
curves.append(curve)
with open('static/curves/{}'.format(filename), 'w+') as f:
f.write(curve)
return flask.render_template('curves.html', tools=tools, tool='curves', db=db)
@APP.route('/visual-traces/', methods=['GET', 'POST'])
def traces():
db, x = load_db('visual-traces.json')
traces = [db[x]['trace'] for x in db.keys()]
if request.method == 'POST':
if 'trace' not in request.files:
return redirect(request.url)
trace = request.files['trace']
if trace.filename == '':
return redirect(request.url)
if trace and allowed_file(trace.filename):
filename = secure_filename(trace.filename)
trace.save(os.path.join(APP.config['UPLOAD_FOLDER_TRACES'], filename))
if filename not in traces:
x = str(x + 1)
db[x] = {}
db[x]['trace'] = filename
write_db('visual-traces.json', db)
traces.append(filename)
return flask.render_template('visual-traces.html', tools=tools, tool='visual-traces', db=db)
from flask import send_from_directory
@APP.route('/visual-traces/<filename>')
def uploaded_file(filename):
return send_from_directory(APP.config['UPLOAD_FOLDER_TRACES'], filename)
@APP.route('/text-scans/', methods=['GET', 'POST'])
def textscan():
results = {}
data, index = readings.get_pos()
return flask.render_template('text-scans.html', tools=tools, data=data, index=index, results=results)
@APP.route('/text-scans/<word_type>/<word>', methods=['GET', 'POST'])
def textscanresults(word_type, word):
data, index = readings.get_pos()
for ranking, words in data[word_type].items():
for w in words.keys():
if w == word:
results = data[word_type][ranking][word.lower()]
filenames = [document for document, _ in index.items()]
return flask.render_template('text-scans.html', tools=tools, data=data, results=results, filenames=filenames, word=word, word_type=word_type)
# @APP.route('/text-specifics/', methods=['GET', 'POST'])
# def specifics():
# index = readings.load_index()
# return flask.render_template('text-specifics.html', tools=tools, index=index)
if __name__ == '__main__':
APP.debug=True
APP.run(port=5001)