-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
74 lines (57 loc) · 2.01 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import json
import os
from flask import Flask, flash, request, redirect, url_for
from werkzeug.utils import secure_filename
import sqlite3
import subprocess
from threading import Thread
UPLOAD_FOLDER = "./input"
ALLOWED_EXTENSIONS = {'jpg', 'jpeg'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Overige functies, voor afhandelen van proces
def filetype_check(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/start', methods=['POST'])
def start_ai():
# Starten van AI, zodat het proces kan beginnen
# print("Nog niet geimplementeerd, vanwege background thread.")
thread = Thread(target=start_ai_script())
return "App started successfully!"
thread.start()
@app.route('/status', methods=['GET'])
def check_ai():
# Check SQLite database voor status!
con = sqlite3.connect('API/AI_Status')
cur = con.cursor()
# Eerste rij pakken vanwege eerste AI
status = cur.execute("SELECT * FROM info").fetchone()
con.close()
return "Status: " + status[1]
@app.route('/image', methods=['POST'])
def image_input():
# Invoeren van afbeelding in API afbeelding map!
print(request)
print(request.headers)
print(request.files)
if 'file' not in request.files:
return "Bestand niet gevo nden"
file = request.files['file']
# Wanneer geen bestand geselecteerd is
if file.filename == '':
return "Geen bestand geselecteerd"
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return "Bestand ontvangen"
# Resultaten app route GET
# Dictionary terug geven met resultaten en anchor filenamen!
# Dit invullen wanneer AI resultaten
@app.route('/results', methods=['GET'])
def check_results():
with open("API/results.json", "r") as results_file:
results = json.load(results_file)
return results
def start_ai_script():
subprocess.call(["python", "siamese_network.py"])