<reponame>blue-fox-maker/LFS-test<filename>app.py<gh_stars>0
from os import read
from flask import (
    Flask,
    request,
    render_template,
    redirect,
    url_for,
    send_from_directory,
)

from firstOrderModel.demo import run

from time import sleep

app = Flask(__name__)


@app.route("/", methods=["GET", "POST"])
def index():
    if request.method == "POST":
        try:
            f = request.files["file"]
            f.save("static/images/" + f.filename)

            # add first-order-model
            # return render_template("result.html", _filename=f.filename[:-4])

            return redirect(url_for("choose_video", image_name=f.filename))
        except:
            pass
        # return render_template("result.html", _filename=f.filename[:-4])
    return render_template("index.html")


@app.route("/choose_video?image=<image_name>")
def choose_video(image_name):
    return render_template("choose_video.html", image_name=image_name)


@app.route("/loading?image=<image_name>&video=<video_name>")
def loading(image_name, video_name):
    return render_template("loading.html", image_name=image_name, video_name=video_name)


@app.route("/result?image=<image_name>&video=<video_name>")
def result(image_name, video_name):
    run(image_name, video_name)
    return render_template("result.html", image_name=image_name, video_name=video_name)


@app.route("/download?video=<video>")
def download(video):
    try:
        return send_from_directory("static/results", video, as_attachment=True)
    except:
        return "<h1>文件不存在或无法下载</h1>"


if __name__ == "__main__":
    app.run()

from os import read
from flask import (
    Flask,
    request,
    render_template,
    redirect,
    url_for,
    send_from_directory,
)

from firstOrderModel.demo import run

from time import sleep

app = Flask(__name__)


@app.route("/", methods=["GET", "POST"])
def index():
    if request.method == "POST":
        try:
            f = request.files["file"]
            f.save("static/images/" + f.filename)

            # add first-order-model
            # return render_template("result.html", _filename=f.filename[:-4])

            return redirect(url_for("choose_video", image_name=f.filename))
        except:
            pass
        # return render_template("result.html", _filename=f.filename[:-4])
    return render_template("index.html")


@app.route("/choose_video?image=<image_name>")
def choose_video(image_name):
    return render_template("choose_video.html", image_name=image_name)


@app.route("/loading?image=<image_name>&video=<video_name>")
def loading(image_name, video_name):
    return render_template("loading.html", image_name=image_name, video_name=video_name)


@app.route("/result?image=<image_name>&video=<video_name>")
def result(image_name, video_name):
    run(image_name, video_name)
    return render_template("result.html", image_name=image_name, video_name=video_name)


@app.route("/download?video=<video>")
def download(video):
    try:
        return send_from_directory("static/results", video, as_attachment=True)
    except:
        return "<h1>文件不存在或无法下载</h1>"


if __name__ == "__main__":
    app.run()
# add first-order-model # return render_template("result.html", _filename=f.filename[:-4]) # return render_template("result.html", _filename=f.filename[:-4])