Spaces:
Runtime error
Runtime error
| import flask | |
| from flask import request, jsonify, send_from_directory, render_template_string | |
| import os | |
| app = flask.Flask(__name__, template_folder="./") | |
| app.config['DEBUG'] = True | |
| def online(): | |
| return render_template('online.html') | |
| UPLOAD_FOLDER = 'static' | |
| IMAGE_FILENAME = 'latest_image.jpg' | |
| # Создание директории, если она не существует | |
| if not os.path.exists(UPLOAD_FOLDER): | |
| os.makedirs(UPLOAD_FOLDER) | |
| def upload_file(): | |
| if 'file' not in request.files: | |
| return "No file part", 400 | |
| file = request.files['file'] | |
| if file.filename == '': | |
| return "No selected file", 400 | |
| file.save(os.path.join(UPLOAD_FOLDER, IMAGE_FILENAME)) | |
| return "File uploaded successfully", 200 | |
| def get_image(): | |
| return send_from_directory(UPLOAD_FOLDER, IMAGE_FILENAME) | |
| def index(): | |
| html = ''' | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Camera Image</title> | |
| </head> | |
| <body> | |
| <h1>Latest Image</h1> | |
| <img id="cameraImage" src="/image" alt="Image" style="width:100%;"> | |
| <script> | |
| setInterval(function(){ | |
| var image = document.getElementById("cameraImage"); | |
| image.src = "/image?" + new Date().getTime(); | |
| }, 10000); // обновление каждые 10 секунд | |
| </script> | |
| </body> | |
| </html> | |
| ''' | |
| return render_template_string(html) | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860))) |