Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
import
|
| 2 |
-
from flask import request, jsonify
|
| 3 |
import os
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
app = flask.Flask(__name__, template_folder="./")
|
| 8 |
app.config['DEBUG'] = True
|
|
@@ -19,7 +19,51 @@ def index():
|
|
| 19 |
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
|
|
|
|
| 1 |
+
from flask import Flask, request, send_from_directory, render_template_string
|
|
|
|
| 2 |
import os
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
|
| 7 |
app = flask.Flask(__name__, template_folder="./")
|
| 8 |
app.config['DEBUG'] = True
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
+
app = Flask(__name__)
|
| 23 |
+
UPLOAD_FOLDER = 'static'
|
| 24 |
+
IMAGE_FILENAME = 'latest_image.jpg'
|
| 25 |
+
|
| 26 |
+
# Создание директории, если она не существует
|
| 27 |
+
if not os.path.exists(UPLOAD_FOLDER):
|
| 28 |
+
os.makedirs(UPLOAD_FOLDER)
|
| 29 |
|
| 30 |
+
@app.route('/upload', methods=['POST'])
|
| 31 |
+
def upload_file():
|
| 32 |
+
if 'file' not in request.files:
|
| 33 |
+
return "No file part", 400
|
| 34 |
+
file = request.files['file']
|
| 35 |
+
if file.filename == '':
|
| 36 |
+
return "No selected file", 400
|
| 37 |
+
file.save(os.path.join(UPLOAD_FOLDER, IMAGE_FILENAME))
|
| 38 |
+
return "File uploaded successfully", 200
|
| 39 |
+
|
| 40 |
+
@app.route('/image')
|
| 41 |
+
def get_image():
|
| 42 |
+
return send_from_directory(UPLOAD_FOLDER, IMAGE_FILENAME)
|
| 43 |
+
|
| 44 |
+
@app.route('/')
|
| 45 |
+
def index():
|
| 46 |
+
html = '''
|
| 47 |
+
<!DOCTYPE html>
|
| 48 |
+
<html lang="en">
|
| 49 |
+
<head>
|
| 50 |
+
<meta charset="UTF-8">
|
| 51 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 52 |
+
<title>Camera Image</title>
|
| 53 |
+
</head>
|
| 54 |
+
<body>
|
| 55 |
+
<h1>Latest Camera Image</h1>
|
| 56 |
+
<img id="cameraImage" src="/image" alt="Camera Image" style="width:100%;">
|
| 57 |
+
<script>
|
| 58 |
+
setInterval(function(){
|
| 59 |
+
var image = document.getElementById("cameraImage");
|
| 60 |
+
image.src = "/image?" + new Date().getTime();
|
| 61 |
+
}, 10000); // обновление каждые 10 секунд
|
| 62 |
+
</script>
|
| 63 |
+
</body>
|
| 64 |
+
</html>
|
| 65 |
+
'''
|
| 66 |
+
return render_template_string(html)
|
| 67 |
|
| 68 |
|
| 69 |
|