style-transfer / app.py
DarkMrdan's picture
Upload 4 files
39f74d8
raw
history blame
1.25 kB
from flask import Flask, render_template, request, redirect, url_for
import os
from werkzeug.utils import secure_filename
from neural_style import main
app = Flask(__name__)
# 首页,用于上传图片和显示结果
@app.route('/', methods=['GET', 'POST'])
def upload_and_process():
if request.method == 'POST':
# 获取上传的图片列表
images = [request.files['image1'], request.files['image2']]
filenames = []
for image in images:
if image:
# 使用secure_filename获取安全的文件名
filename = secure_filename(image.filename)
print(filename)
# 保存上传的图片到本地
image.save(os.path.join('static', filename))
filenames.append(filename)
# 调用AI模型对图片进行处理(在这里,您需要编写AI模型的代码)
main(filenames[0], filenames[1])
# 返回结果页面并展示处理后的图片
return render_template('index.html', image_path="out.png", \
filename1=filenames[0], filename2=filenames[1])
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)