我想让图像只在我的机器上实时显示。想想谷歌图片的基本版本吧。用户输入“红色锤子”,我给他们看一张红色锤子的图片
问题是刷新率。我更新要显示的图像文件,当我直接将其作为http://127.0.0.1:6007/static/tree.jpg查找时,会立即得到最新的jpg。然后,奇怪的是,在我查找类似http://127.0.0.1:6007/static/tree.jpg的内容后,图像在初始的http://127.0.0.1:6007上发生了变化!在
我的设置:
在static/目录中,tree.jpg:
模板/
在显示.html
在templates/,show.html:
Text-to-Image Synthesis
Input to Generator:
在索引.html
和index.html:
^{pr2}$
除了show.html显示src=...行上的图像外,这两个是相同的。在
在服务器.py在#!/usr/bin/env python2.7
import os
from flask import Flask, request, render_template, g, redirect, Response, send_from_directory
tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
app = Flask(__name__, template_folder=tmpl_dir)
@app.route('/')
def index():
return render_template("index.html")
@app.route('/generator', methods=['POST'])
def generator():
# save typed-in text
text = request.form['input_text']
filename = "/home/ubuntu/icml2016/scripts/cub_queries.txt"
with open(filename, "a+") as f:
f.write(text + "\n")
"""
print('start')
subprocess.call('./scripts/demo_cub.sh', shell=True) # change the image in the background
print('end')
"""
return render_template("show.html")
if __name__ == "__main__":
HOST='0.0.0.0'
PORT=6007
app.run(host=HOST, port=PORT)
所以现在如果我把所有的东西都给了你,你应该可以打电话给python3 server.py并看到这个:
如果您在框中输入“嗨”,它将显示以下内容:
但当我改变树.jpg到背景中的其他图像并输入其他内容,我无法获得我正在寻找的即时图像更新。换句话说,那棵树不会成为最近的一棵树:(我们想在我的基本网页上看到莫里美丽的脸。)