import os from flask import Flask, request, send_from_directory, render_template_string, render_template app = Flask(__name__, template_folder="./") app.config['DEBUG'] = True UPLOAD_FOLDER = 'static' IMAGE_FILENAME = 'latest_image.jpg' # Создание директории, если она не существует if not os.path.exists(UPLOAD_FOLDER): os.makedirs(UPLOAD_FOLDER) @app.route('/online', methods=['GET']) def online(): return render_template('online.html') @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(UPLOAD_FOLDER, IMAGE_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

Upload Image

Latest Image

Image ''' return render_template_string(html) if __name__ == '__main__': app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))