mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-22 22:34:25 -07:00
Sockets
This commit is contained in:
parent
85dc94bf0c
commit
9ed85c4c9a
3 changed files with 54 additions and 33 deletions
|
@ -1,6 +1,7 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from flask import Flask, send_file, Response, render_template, render_template_string, request, g
|
from flask import Flask, send_file, Response, render_template, render_template_string, request, g
|
||||||
# from flask_socketio import SocketIO
|
from flask_socketio import SocketIO
|
||||||
|
|
||||||
|
|
||||||
def create_flask_app(s2c, c2s, s2flask, args):
|
def create_flask_app(s2c, c2s, s2flask, args):
|
||||||
|
@ -42,16 +43,23 @@ def create_flask_app(s2c, c2s, s2flask, args):
|
||||||
request.environ.get('werkzeug.server.shutdown')()
|
request.environ.get('werkzeug.server.shutdown')()
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/update', methods=['POST'])
|
||||||
|
def update():
|
||||||
|
send(c2s, 'update')
|
||||||
|
return '', 204
|
||||||
|
|
||||||
|
@app.route('/next_preview', methods=['POST'])
|
||||||
|
def next_preview():
|
||||||
|
send(c2s, 'next_preview')
|
||||||
|
return '', 204
|
||||||
|
|
||||||
|
@app.route('/change_history_range', methods=['POST'])
|
||||||
|
def change_history_range():
|
||||||
|
send(c2s, 'change_history_range')
|
||||||
|
return '', 204
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
if request.method == 'POST':
|
|
||||||
if 'update' in request.form:
|
|
||||||
send_and_wait(c2s, 'update')
|
|
||||||
elif 'next_preview' in request.form:
|
|
||||||
send_and_wait(c2s, 'next_preview')
|
|
||||||
elif 'change_history_range' in request.form:
|
|
||||||
send_and_wait(c2s, 'change_history_range')
|
|
||||||
# return '', 204
|
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
# @app.route('/preview_image')
|
# @app.route('/preview_image')
|
||||||
|
@ -62,7 +70,11 @@ def create_flask_app(s2c, c2s, s2flask, args):
|
||||||
def preview_image():
|
def preview_image():
|
||||||
return send_file(preview_file, mimetype='image/jpeg', cache_timeout=-1)
|
return send_file(preview_file, mimetype='image/jpeg', cache_timeout=-1)
|
||||||
|
|
||||||
return app
|
socketio = SocketIO(app)
|
||||||
|
@socketio.on('connect')
|
||||||
|
def connect():
|
||||||
|
pass
|
||||||
|
return socketio, app
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,40 +6,49 @@
|
||||||
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
|
||||||
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
|
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"
|
||||||
|
integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I="
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
<title>Flask Server Demonstration</title>
|
<title>Flask Server Demonstration</title>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
$(function() {
|
||||||
$('button#save').click(function() {
|
$('button#save').click(function() {
|
||||||
$.post('/save');
|
$.post("{{ url_for('save') }}");
|
||||||
});
|
});
|
||||||
|
|
||||||
$('button#exit').click(function() {
|
$('button#exit').click(function() {
|
||||||
$.post('/exit');
|
$.post("{{ url_for('exit') }}");
|
||||||
});
|
});
|
||||||
|
|
||||||
// $('button#update').click(function() {
|
$('button#update').click(function() {
|
||||||
// $.post('/update');
|
$.post("{{ url_for('update') }}");
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// $('button#next_preview').click(function() {
|
$('button#next_preview').click(function() {
|
||||||
// $.post('/next_preview');
|
$.post("{{ url_for('next_preview') }}");
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// $('button#change_history_range').click(function() {
|
$('button#change_history_range').click(function() {
|
||||||
// $.post('/change_history_range');
|
$.post("{{ url_for('change_history_range') }}");
|
||||||
// });
|
});
|
||||||
|
|
||||||
|
const socket = io.connect('127.0.0.1:5000');
|
||||||
|
socket.on('preview', function() {
|
||||||
|
console.log('new preview!');
|
||||||
|
$('img#preview').src = "{{ url_for('preview_image') }}?random="+new Date().getTime();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Flask Server Demonstration</h1>
|
<h1>Flask Server Demonstration</h1>
|
||||||
<form action="/" method="post">
|
<div>
|
||||||
<button class='btn btn-default' id='save'>Save</button>
|
<button class='btn btn-default' id='save'>Save</button>
|
||||||
<button class='btn btn-default' id='exit'>Exit</button>
|
<button class='btn btn-default' id='exit'>Exit</button>
|
||||||
<button class='btn btn-default' id='update' name="update" value="update">Update</button>
|
<button class='btn btn-default' id='update'>Update</button>
|
||||||
<button class='btn btn-default' id='next_preview' name="next_preview" value="next_preview">Next preview</button>
|
<button class='btn btn-default' id='next_preview'>Next preview</button>
|
||||||
<button class='btn btn-default' id='change_history_range' name="change_history_range" value="change_history_range">Change History Range</button>
|
<button class='btn btn-default' id='change_history_range'>Change History Range</button>
|
||||||
</form>
|
</div>
|
||||||
<img src="{{ url_for('preview_image') }}">
|
<img id='preview' src="{{ url_for('preview_image') }}">
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -296,8 +296,8 @@ def main(args, device_args):
|
||||||
|
|
||||||
e.wait() #Wait for inital load to occur.
|
e.wait() #Wait for inital load to occur.
|
||||||
|
|
||||||
flask_app = create_flask_app(s2c, c2s, s2flask, args)
|
socketio, flask_app = create_flask_app(s2c, c2s, s2flask, args)
|
||||||
flask_t = threading.Thread(target=flask_app.run, kwargs={'debug': True, 'use_reloader': False})
|
flask_t = threading.Thread(target=socketio.run, args=(flask_app,), kwargs={'debug': True, 'use_reloader': False})
|
||||||
flask_t.start()
|
flask_t.start()
|
||||||
|
|
||||||
wnd_name = "Training preview"
|
wnd_name = "Training preview"
|
||||||
|
@ -366,7 +366,7 @@ def main(args, device_args):
|
||||||
preview_file = str(model_path / filename)
|
preview_file = str(model_path / filename)
|
||||||
cv2.imwrite(preview_file, preview_pane_image)
|
cv2.imwrite(preview_file, preview_pane_image)
|
||||||
s2flask.put({'op': 'show'})
|
s2flask.put({'op': 'show'})
|
||||||
# socketio.emit('some event', {'data': 42})
|
socketio.emit('preview', {})
|
||||||
|
|
||||||
# cv2.imshow(wnd_name, preview_pane_image)
|
# cv2.imshow(wnd_name, preview_pane_image)
|
||||||
is_showing = True
|
is_showing = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue