def upload(): tag_db = db.execute( "SELECT DISTINCT tag FROM tag WHERE user_id = 1 ORDER BY tag") tags = [] for tag in tag_db: tags.append(tag['tag']) if request.method == "POST": file = request.files['file'] desc = request.form.get('desc').lower() tag = request.form.get('tag').lower() filename = secure_filename(file.filename).lower() file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) image_id = db.execute( "INSERT INTO img (name, desc) VALUES(:name, :desc)", name=filename, desc=desc) convert_speech(desc, str(image_id)) db.execute( "INSERT INTO tag (image_id, user_id, tag) VALUES(:image_id, :user_id, :tag)", image_id=image_id, user_id=session['user_id'], tag=tag) flash("File Uploaded Successfully") return render_template("upload.html", filename=filename, tags=tags, desc=desc, tag=tag) else: return render_template("upload.html", tags=tags)
def convert(): if request.method == "POST": text = request.form.get('text') image_id = request.form.get('img_id') convert_speech(text, image_id) flash("Convertion successful...") return redirect("/convert") else: return render_template("convert.html")
def edit(): if request.method == "POST": if request.form.get('desc'): img_id = int(request.form.get('id')) desc = request.form.get('desc').lower() convert_speech(desc, request.form.get('id')) db.execute("UPDATE img SET desc = :desc WHERE id = :img_id", desc=desc, img_id=img_id) if request.form.get('tag'): img_id = int(request.form.get('id')) tag = request.form.get('tag') db.execute("UPDATE tag SET tag = :tag WHERE image_id = :img_id", tag=tag, img_id=img_id) if request.form.get('del'): img_id = int(request.form.get('id')) db_img = db.execute("SELECT * FROM img WHERE id = :img_id", img_id=img_id) print(db_img) for img in db_img: os.remove("static/uploads/" + img['name']) os.remove("static/audio/" + str(img['id']) + ".mp3") db.execute("DELETE FROM tag WHERE image_id = :img_id", img_id=img_id) db.execute("DELETE FROM img WHERE id = :img_id", img_id=img_id) PECS_db = db.execute( "SELECT id, name, desc, tag FROM img JOIN tag ON image_id = id WHERE user_id = :user_id ORDER BY id", user_id=session['user_id']) if len(PECS_db) < 0: return redirect("/edit") return "0" else: PECS_db = db.execute( "SELECT id, name, desc, tag FROM img JOIN tag ON image_id = id WHERE user_id = :user_id AND tag != :tag ORDER BY id", user_id=session['user_id'], tag="favourites") tag_db = db.execute( "SELECT DISTINCT tag FROM tag WHERE tag != :tag ORDER BY tag", tag="favourites") tags = [] for tag in tag_db: tags.append(tag['tag']) return render_template("edit.html", PECS_db=PECS_db, tags=tags)