Created
November 14, 2022 12:21
-
-
Save Sachin-crypto/4479f7611f371321e19a8cc1ab3b514f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importing required libs | |
from flask import Flask, render_template, request | |
from model import preprocess_img, predict_result | |
# Instantiating flask app | |
app = Flask(__name__) | |
# Home route | |
@app.route("/") | |
def main(): | |
return render_template("index.html") | |
# Prediction route | |
@app.route('/prediction', methods=['POST']) | |
def predict_image_file(): | |
try: | |
if request.method == 'POST': | |
img = preprocess_img(request.files['file'].stream) | |
pred = predict_result(img) | |
return render_template("result.html", predictions=str(pred)) | |
except: | |
error = "File cannot be processed." | |
return render_template("result.html", err=error) | |
# Driver code | |
if __name__ == "__main__": | |
app.run(port=9000, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment