Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +35 -113
templates/index.html
CHANGED
@@ -3,118 +3,40 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Camera
|
7 |
-
<
|
8 |
-
#videoElement {
|
9 |
-
width: 100%;
|
10 |
-
height: auto;
|
11 |
-
}
|
12 |
-
#camera-controls {
|
13 |
-
display: flex;
|
14 |
-
justify-content: space-between;
|
15 |
-
margin-top: 10px;
|
16 |
-
}
|
17 |
-
#capture-button {
|
18 |
-
margin-top: 10px;
|
19 |
-
}
|
20 |
-
</style>
|
21 |
</head>
|
22 |
-
<body>
|
23 |
-
|
24 |
-
<h1>
|
25 |
-
|
26 |
-
|
27 |
-
<
|
28 |
-
|
29 |
-
|
30 |
-
<
|
31 |
-
|
32 |
-
|
33 |
-
<
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
<div id="
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
</div>
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
.then(devices => {
|
55 |
-
devices.forEach(device => {
|
56 |
-
if (device.kind === 'videoinput') {
|
57 |
-
currentStream = device.deviceId;
|
58 |
-
startStream(currentStream);
|
59 |
-
}
|
60 |
-
});
|
61 |
-
})
|
62 |
-
.catch(err => console.error("Error accessing camera:", err));
|
63 |
-
}
|
64 |
-
|
65 |
-
function startStream(deviceId) {
|
66 |
-
navigator.mediaDevices.getUserMedia({
|
67 |
-
video: { deviceId: { exact: deviceId } }
|
68 |
-
})
|
69 |
-
.then(stream => {
|
70 |
-
videoElement.srcObject = stream;
|
71 |
-
videoStream = stream;
|
72 |
-
})
|
73 |
-
.catch(err => console.error("Error accessing stream:", err));
|
74 |
-
}
|
75 |
-
|
76 |
-
function switchCamera() {
|
77 |
-
if (videoStream) {
|
78 |
-
videoStream.getTracks().forEach(track => track.stop());
|
79 |
-
}
|
80 |
-
startCamera();
|
81 |
-
}
|
82 |
-
|
83 |
-
function captureImage() {
|
84 |
-
let canvas = document.createElement('canvas');
|
85 |
-
canvas.width = videoElement.videoWidth;
|
86 |
-
canvas.height = videoElement.videoHeight;
|
87 |
-
canvas.getContext('2d').drawImage(videoElement, 0, 0, canvas.width, canvas.height);
|
88 |
-
|
89 |
-
let imageData = canvas.toDataURL('image/jpeg');
|
90 |
-
capturedImage.src = imageData;
|
91 |
-
|
92 |
-
capturedImageSection.style.display = 'block';
|
93 |
-
|
94 |
-
// Sending the captured image to Flask server
|
95 |
-
fetch('/capture', {
|
96 |
-
method: 'POST',
|
97 |
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
98 |
-
body: 'image=' + encodeURIComponent(imageData)
|
99 |
-
}).then(response => response.json())
|
100 |
-
.then(data => console.log(data.message));
|
101 |
-
}
|
102 |
-
|
103 |
-
function retakeImage() {
|
104 |
-
capturedImageSection.style.display = 'none';
|
105 |
-
startCamera();
|
106 |
-
}
|
107 |
-
|
108 |
-
function submitImage() {
|
109 |
-
fetch('/post_to_instagram', {
|
110 |
-
method: 'POST'
|
111 |
-
})
|
112 |
-
.then(response => response.json())
|
113 |
-
.then(data => {
|
114 |
-
alert(data.message);
|
115 |
-
});
|
116 |
-
}
|
117 |
-
</script>
|
118 |
-
|
119 |
</body>
|
120 |
-
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Flask Camera App</title>
|
7 |
+
<link href="{{ url_for('static', filename='css/tailwind.css') }}" rel="stylesheet">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
</head>
|
9 |
+
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
10 |
+
<div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-lg">
|
11 |
+
<h1 class="text-2xl font-bold mb-4 text-center">Capture & Upload</h1>
|
12 |
+
<div class="relative">
|
13 |
+
<video id="video" class="w-full rounded" autoplay></video>
|
14 |
+
<canvas id="canvas" class="hidden"></canvas>
|
15 |
+
<img id="capturedImage" class="w-full rounded hidden" src="">
|
16 |
+
</div>
|
17 |
+
<div class="flex justify-center space-x-4 mt-4">
|
18 |
+
<button id="cameraBtn" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
|
19 |
+
<svg class="w-6 h-6 inline" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
20 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 9a2 2 0 012-2h2l2-2h6l2 2h2a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"/>
|
21 |
+
<circle cx="12" cy="13" r="4"/>
|
22 |
+
</svg>
|
23 |
+
Open Camera
|
24 |
+
</button>
|
25 |
+
</div>
|
26 |
+
<div id="cameraControls" class="hidden mt-4">
|
27 |
+
<div class="flex justify-center space-x-4 mb-4">
|
28 |
+
<button id="frontCam" class="bg-gray-300 text-black px-4 py-2 rounded hover:bg-gray-400">Front Camera</button>
|
29 |
+
<button id="backCam" class="bg-gray-300 text-black px-4 py-2 rounded hover:bg-gray-400">Back Camera</button>
|
30 |
+
</div>
|
31 |
+
<button id="captureBtn" class="bg-green-500 text-white w-full py-2 rounded hover:bg-green-600">Capture</button>
|
32 |
+
</div>
|
33 |
+
<div id="postCapture" class="hidden mt-4">
|
34 |
+
<div class="flex justify-center space-x-4">
|
35 |
+
<button id="retakeBtn" class="bg-red-500 text-white px-4 py-2 rounded hover:bg-red-600">Retake</button>
|
36 |
+
<button id="uploadBtn" class="bg-purple-500 text-white px-4 py-2 rounded hover:bg-purple-600">Upload to Instagram</button>
|
37 |
+
</div>
|
38 |
+
</div>
|
39 |
+
</div>
|
40 |
+
<script src="{{ url_for('static', filename='js/camera.js') }}"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
</body>
|
42 |
+
</html>
|