|
from flask import Flask, request, render_template, redirect, jsonify |
|
from flask_jsglue import JSGlue |
|
import util |
|
import os |
|
from werkzeug.utils import secure_filename |
|
|
|
application = Flask(__name__) |
|
|
|
|
|
jsglue = JSGlue() |
|
jsglue.init_app(application) |
|
|
|
util.load_artifacts() |
|
|
|
@application.route("/") |
|
def home(): |
|
return render_template("home.html") |
|
|
|
|
|
@application.route("/classifywaste", methods = ["POST"]) |
|
def classifywaste(): |
|
image_data = request.files["file"] |
|
|
|
basepath = os.path.dirname(__file__) |
|
image_path = os.path.join(basepath, "uploads", secure_filename(image_data.filename)) |
|
image_data.save(image_path) |
|
|
|
predicted_value, details, video1, video2 = util.classify_waste(image_path) |
|
os.remove(image_path) |
|
return jsonify(predicted_value=predicted_value, details=details, video1=video1, video2=video2) |
|
|
|
|
|
@application.errorhandler(404) |
|
def page_not_found(e): |
|
|
|
return render_template("404.html"), 404 |
|
|
|
if __name__ == "__main__": |
|
application.run() |