diff --git a/app.py b/app.py index 69ca0bb..b4bfd14 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, request, redirect, url_for, flash, session +from flask import Flask, render_template, request, redirect, url_for, flash, session, jsonify from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from datetime import datetime @@ -6,6 +6,7 @@ from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.utils import secure_filename import os from config import Config +import random app = Flask(__name__) app.config.from_object(Config) @@ -1438,6 +1439,20 @@ def seed_db(): )) db.session.commit() +@app.route('/recognize-plant', methods=['GET', 'POST']) +def recognize_plant(): + if request.method == 'GET': + return render_template('recognize_plant.html') + + # For proof of concept, just return a random plant + plants = Plant.query.all() + if not plants: + flash('No plants found in the database.', 'warning') + return redirect(url_for('home')) + + random_plant = random.choice(plants) + return jsonify({'redirect': url_for('plant', plant_id=random_plant.id)}) + if __name__ == "__main__": with app.app_context(): db.create_all() # Create all tables diff --git a/templates/base.html b/templates/base.html index 438d9e4..23ff8e2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -10,25 +10,21 @@ - +
{% with messages = get_flashed_messages(with_categories=true) %} diff --git a/templates/recognize_plant.html b/templates/recognize_plant.html new file mode 100644 index 0000000..4677cbc --- /dev/null +++ b/templates/recognize_plant.html @@ -0,0 +1,129 @@ +{% extends "base.html" %} + +{% block title %}Recognize Plant{% endblock %} + +{% block content %} +
+

Plant Recognition

+ +
+ +
+

Take a Photo

+
+ + +
+ Camera preview will appear here +
+
+
+ + +
+
+ + +
+

Upload Image

+
+
+ +
+ +
+
+
+ + +
+ + +{% endblock %} \ No newline at end of file