Cat_Detector is other file where class is_cat is checking if there are any cats in the picture.
The upload part i took from flask documentation.
If frontend was written in ASP.net mvc, how i make it used in this? Frontend app has to use POST to upload image to this api, then frontend has to request GET for answer about number of cats in picture, so i need to prepare api for that.
Sorry if my code hurts your eyes, glad to hear that you are ready to help. I don't want this project to be done by someone else, I need to understand this for the future.
I hope that my questions are more specific now
import os
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, flash
from Cat_Detector import is_cat
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = '/cats'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def index():
#something connected with frontend i guess, but found no examples of this
return "test"
@app.route('/upload', methods=['POST'])
def upload():
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
@app.route('/cat', methods=['GET'])
def cat():
#what should i put instead of questionmark?
return is_cat(?)
if __name__ == "__main__":
app.run(debug=True)