Spaces:
Sleeping
Sleeping
Update static/js/script.js
Browse files- static/js/script.js +42 -0
static/js/script.js
CHANGED
@@ -4,11 +4,16 @@ $(document).ready(function() {
|
|
4 |
const capturedImage = document.getElementById('capturedImage');
|
5 |
const hfResult = document.getElementById('hfResult');
|
6 |
const cameraSelect = document.getElementById('cameraSelect');
|
|
|
7 |
let stream = null;
|
|
|
8 |
|
9 |
// Open camera
|
10 |
$('#openCamera').click(function() {
|
11 |
$('#cameraContainer').show();
|
|
|
|
|
|
|
12 |
startCamera(cameraSelect.value);
|
13 |
});
|
14 |
|
@@ -37,6 +42,8 @@ $(document).ready(function() {
|
|
37 |
capturedImage.src = response.image_url;
|
38 |
capturedImage.style.display = 'block';
|
39 |
hfResult.textContent = JSON.stringify(response.hf_result, null, 2);
|
|
|
|
|
40 |
stopCamera();
|
41 |
$('#cameraContainer').hide();
|
42 |
} else {
|
@@ -49,6 +56,41 @@ $(document).ready(function() {
|
|
49 |
});
|
50 |
});
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
function startCamera(facingMode) {
|
53 |
const constraints = {
|
54 |
video: { facingMode: facingMode }
|
|
|
4 |
const capturedImage = document.getElementById('capturedImage');
|
5 |
const hfResult = document.getElementById('hfResult');
|
6 |
const cameraSelect = document.getElementById('cameraSelect');
|
7 |
+
const actionButtons = document.getElementById('actionButtons');
|
8 |
let stream = null;
|
9 |
+
let currentImageUrl = null;
|
10 |
|
11 |
// Open camera
|
12 |
$('#openCamera').click(function() {
|
13 |
$('#cameraContainer').show();
|
14 |
+
actionButtons.style.display = 'none';
|
15 |
+
capturedImage.style.display = 'none';
|
16 |
+
hfResult.textContent = '';
|
17 |
startCamera(cameraSelect.value);
|
18 |
});
|
19 |
|
|
|
42 |
capturedImage.src = response.image_url;
|
43 |
capturedImage.style.display = 'block';
|
44 |
hfResult.textContent = JSON.stringify(response.hf_result, null, 2);
|
45 |
+
actionButtons.style.display = 'block';
|
46 |
+
currentImageUrl = response.image_url;
|
47 |
stopCamera();
|
48 |
$('#cameraContainer').hide();
|
49 |
} else {
|
|
|
56 |
});
|
57 |
});
|
58 |
|
59 |
+
// Retake button
|
60 |
+
$('#retakeButton').click(function() {
|
61 |
+
$('#cameraContainer').show();
|
62 |
+
actionButtons.style.display = 'none';
|
63 |
+
capturedImage.style.display = 'none';
|
64 |
+
hfResult.textContent = '';
|
65 |
+
startCamera(cameraSelect.value);
|
66 |
+
});
|
67 |
+
|
68 |
+
// Upload to Instagram
|
69 |
+
$('#uploadButton').click(function() {
|
70 |
+
if (!currentImageUrl) {
|
71 |
+
alert('No image to upload.');
|
72 |
+
return;
|
73 |
+
}
|
74 |
+
$.ajax({
|
75 |
+
type: 'POST',
|
76 |
+
url: '/upload_instagram',
|
77 |
+
data: { image_url: currentImageUrl },
|
78 |
+
success: function(response) {
|
79 |
+
if (response.status === 'success') {
|
80 |
+
alert('Image uploaded to Instagram successfully!');
|
81 |
+
actionButtons.style.display = 'none';
|
82 |
+
capturedImage.style.display = 'none';
|
83 |
+
hfResult.textContent = '';
|
84 |
+
} else {
|
85 |
+
alert('Error uploading to Instagram: ' + response.message);
|
86 |
+
}
|
87 |
+
},
|
88 |
+
error: function() {
|
89 |
+
alert('Failed to upload image to Instagram.');
|
90 |
+
}
|
91 |
+
});
|
92 |
+
});
|
93 |
+
|
94 |
function startCamera(facingMode) {
|
95 |
const constraints = {
|
96 |
video: { facingMode: facingMode }
|