36 lines
1003 B
Python
36 lines
1003 B
Python
from flask import Flask, Response, render_template
|
|
import threading
|
|
import io
|
|
import translate
|
|
app = Flask(__name__)
|
|
|
|
# Global variable to hold the current image
|
|
def curr_image():
|
|
return translate.latest_image
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
|
|
@app.route('/image')
|
|
def stream_image():
|
|
if curr_image() is None:
|
|
return "No image generated yet.", 503
|
|
file_object = io.BytesIO()
|
|
curr_image().save(file_object, 'PNG')
|
|
file_object.seek(0)
|
|
response = Response(file_object.getvalue(), mimetype='image/png')
|
|
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate' # HTTP 1.1
|
|
response.headers['Pragma'] = 'no-cache' # HTTP 1.0
|
|
response.headers['Expires'] = '0' # Proxies
|
|
|
|
return response
|
|
|
|
if __name__ == '__main__':
|
|
# Start the image updating thread
|
|
threading.Thread(target=translate.main, daemon=True).start()
|
|
|
|
# Start the Flask web server
|
|
app.run(host='0.0.0.0', port=5000, debug=True)
|