from flask import Flask, request, send_from_directory, render_template_string from flask_socketio import SocketIO, send, emit import os UPLOAD_FOLDER = 'static' IMAGE_FILENAME = 'latest_image.jpg' app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER socketio = SocketIO(app) # Создание директории, если она не существует if not os.path.exists(UPLOAD_FOLDER): os.makedirs(UPLOAD_FOLDER) @app.route('/upload', methods=['POST']) def upload_file(): if 'photo' not in request.files: return "No file part", 400 file = request.files['photo'] if file.filename == '': return "No selected file", 400 save_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) file.save(save_path) return f"File uploaded successfully and saved to {save_path}", 200 @app.route('/image', methods=['GET']) def get_image(): return send_from_directory(UPLOAD_FOLDER, IMAGE_FILENAME) @app.route('/') def index(): html = ''' Camera Image

Latest Image

Image ''' return render_template_string(html) @app.route('/chat') def chat(): return flask.render_template('chat.html') @app.route('/chat2') def chat2(): return flask.render_template('chat2.html') @socketio.on('message') def handle_message(message): print('Received message: ' + message) send(message, broadcast=True) @app.route('/upload_form') def upload_form(): html = ''' Upload Image

Upload Image

''' return render_template_string(html) @socketio.on('message') def handle_message(msg): print('Message: ' + msg) send(msg, broadcast=True) @socketio.on('json') def handle_json(json): print('JSON: ' + str(json)) send(json, json=True, broadcast=True) if __name__ == '__main__': socketio.run(app, host='0.0.0.0', port=7860, allow_unsafe_werkzeug=True)