plant recognition
This commit is contained in:
17
app.py
17
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
|
||||
|
||||
Reference in New Issue
Block a user