-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
253 lines (227 loc) · 11.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html>
<html>
<head>
<title>AI Music Generator</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="./tailsim.css">
<style>
.custom-file-input input[type="file"] {
display: none;
}
.custom-file-input label::before {
content: "Choose File";
background-color: #4a90e2;
color: white;
padding: 8px 12px;
border-radius: 4px;
cursor: pointer;
}
.custom-file-input input[type="file"]:focus+label::before {
outline: dotted;
}
#webcamContainer {
display: none;
}
#snapshotCanvas {
display: none;
}
#btns-2 {
background-color: #4a90e2;
}
</style>
</head>
<body class="bg-gradient-to-b w-full h-full from-pink-600 to-purple-600" style='font-family: Inter;'>
<div class="flex flex-col justify-center items-center">
<div class="w-screen h-full" style='background-image: url("./cover2.png");'>
<div class="pt-10"></div>
<div class="flex flex-col justify-center items-center">
<div class="flex justify-center items-center font-semibold text-transparent text-8xl bg-clip-text">
<img src="./Rectangle 6.png" alt="logo" width="100" height="100">
<span>
< </span>
<div class="text-white text-[64px] font-semibold">Music Mood App</div>
</div>
<div class="p-10 flex flex-col">
<!-- Tab Buttons -->
<div class="flex flex-col justify-center items-center gap-3">
<div id="btn-2" class="flex gap-2 ">
<button id="imageTab" class="bg-blue-400 text-white py-3 px-4 rounded-lg">Image
Upload</button>
<button id="webcamTab" class="bg-gray-400 text-white py-3 px-4 rounded-lg">Webcam</button>
</div>
<div id="imageContainer">
<!-- Existing image upload form -->
<label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
for="imageInput">Upload image</label>
<input
class="block p-3 w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400"
aria-describedby="file_input_help" id="imageInput" type="file" accept="image/*">
<p class="mt-1 text-sm text-gray-500 dark:text-gray-300 font-bold" id="file_input_help">SVG,
PNG, JPG or GIF (MAX. 800x400px).</p>
</div>
<div id="webcamContainer">
<!-- Webcam stream and snapshot button -->
<div id="startWebcam">
<img class="rounded-lg shadow-xl dark:shadow-gray-800" src="takephoto.jpg" width="400"
height="" alt="image description" id="takePhoto">
</div>
<div id="Camera">
<video id="webcamVideo" width="400" height="300" autoplay style="margin: auto;"></video>
<!-- <button id="takeSnapshot">Take Snapshot</button> -->
<canvas id="snapshotCanvas" width="400" height="300"></canvas>
</div>
</div>
</div>
<!-- Tab Content -->
<div class="flex flex-col p-5 gap-3 justify-center items-center">
<button id="generateDescription"
class="flex justify-center items-center w-44 text-white font-bold bg-blue-400 py-2 px-3 rounded-full">Generate
image description</button>
<textarea id="descriptionText" rows="7" cols="50"
class="rounded-lg border-4 border-blue-300 bg-purple-300"></textarea>
</div>
<div class="flex flex-col justify-center items-center gap-3">
<button id="generatePrompt"
class="flex justify-center items-center w-44 text-white font-bold bg-blue-400 py-2 px-3 rounded-full">Generate
prompt for MusicGen</button>
<textarea id="promptText" rows="7" cols="50"
class="rounded-lg border-4 border-blue-300 bg-purple-300"></textarea>
<div></div>
<div class="flex flex-col justify-center items-center gap-3 p-10">
<button id="generateMusic"
class="flex justify-center items-center w-44 text-white font-bold bg-blue-400 py-2 px-3 rounded-full">Generate
music</button>
<p class="mt-1 text-sm text-gray-500 dark:text-gray-300 font-bold" id="loading" style="display: none;">loading... This may take up to a minute</p>
<div class="max-w-md w-full bg-purple-800 p-8 rounded-lg shadow-lg" style="width: 1326px;">
<audio id="audioPlayer" controls class="w-full bg-purple-900 audio-1" />
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Function to read image as Base64
function readFileAsDataURL(inputFile) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = function (event) {
resolve(event.target.result.split(',')[1]);
};
reader.onerror = reject;
reader.readAsDataURL(inputFile);
});
}
// const url = "http://localhost:8000/"
const url = "https://scraper-tool.osc-fr1.scalingo.io/"
const startWebcamButton = document.getElementById("startWebcam");
const imageContainer = document.getElementById("imageContainer");
const webcamContainer = document.getElementById("webcamContainer");
const imageTab = document.getElementById("imageTab");
const webcamTab = document.getElementById("webcamTab");
const takePhotoImage = document.getElementById("takePhoto")
// Function to capture webcam snapshot
function captureSnapshot(video, canvas) {
const ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
return canvas.toDataURL().split(',')[1];
}
// Toggle between tabs
$('#imageTab').click(function () {
$('#imageContainer').show();
$('#webcamContainer').hide();
//switch from bg-blue-400 to bg-gray-400
$('#imageTab').addClass('bg-blue-400');
$('#imageTab').removeClass('bg-gray-400');
$("#webcamTab").addClass('bg-gray-400');
$("#webcamTab").removeClass('bg-blue-400');
});
$('#webcamTab').click(function () {
$('#webcamContainer').show();
$('#imageContainer').hide();
$('#webcamTab').addClass('bg-blue-400');
$('#webcamTab').removeClass('bg-gray-400');
$("#imageTab").addClass('bg-gray-400');
$("#imageTab").removeClass('bg-blue-400');
});
// Add a click event listener to hide the image when clicked
takePhotoImage.addEventListener("click", () => {
takePhotoImage.style.display = "none";
webcamVideo.style.display = "block";
});
startWebcamButton.addEventListener('click', async () => {
takePhoto.style.display = "hidden";
navigator.mediaDevices.getUserMedia({ video: true }).then(function (stream) {
const video = document.getElementById('webcamVideo');
video.srcObject = stream;
});
})
// // Take snapshot and capture data
// $('#takeSnapshot').click(function () {
// const canvas = document.getElementById('snapshotCanvas');
// const video = document.getElementById('webcamVideo');
// captureSnapshot(video, canvas);
// });
// Generate Image Description
$('#generateDescription').click(async function () {
const usingWebcam = $('#webcamContainer').is(':visible');
let imageBase64;
if (usingWebcam) {
const canvas = document.getElementById('snapshotCanvas');
const video = document.getElementById('webcamVideo');
imageBase64 = captureSnapshot(video, canvas);
} else {
const imageFile = $('#imageInput')[0].files[0];
imageBase64 = await readFileAsDataURL(imageFile);
}
$.ajax({
url: url + 'imagedescription',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ image: imageBase64 }),
success: function (data) {
$('#descriptionText').val(data.description);
}
});
});
// Generate Music Prompt
$('#generatePrompt').click(function () {
const description = $('#descriptionText').val();
$.ajax({
url: url + 'musicgenprompt',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ description: description }),
success: function (data) {
$('#promptText').val(data.prompt);
}
});
});
// Generate Music
$('#generateMusic').click(function () {
const prompt = $('#promptText').val();
$("#loading").show();
$.ajax({
url: url + 'generatemusic',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ prompt: prompt }),
success: function (data) {
// const audioData = 'data:audio/wav;base64,' + data.audio;
// $('#audioPlayer').attr('src', audioData);
$('#audioPlayer').attr('src', data.audio_url);
$("#loading").hide();
alert("Music Generated");
},
error: function (error) {
alert(error);
}
});
});
</script>
</body>
</html>