Spaces:
Running
Running
muzammil-eds
commited on
Commit
•
e11c9fd
1
Parent(s):
7b855af
Upload 3 files
Browse files- asset-manifest.json +6 -0
- favicon.ico +0 -0
- index.html +1 -282
asset-manifest.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"main.css": "static/css/main.8254a768.css",
|
3 |
+
"main.css.map": "static/css/main.8254a768.css.map",
|
4 |
+
"main.js": "static/js/main.daa40ad9.js",
|
5 |
+
"main.js.map": "static/js/main.daa40ad9.js.map"
|
6 |
+
}
|
favicon.ico
ADDED
index.html
CHANGED
@@ -1,282 +1 @@
|
|
1 |
-
<!
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Audio Transcription and Similarity Checker</title>
|
7 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
|
8 |
-
<style>
|
9 |
-
body {
|
10 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
11 |
-
background-color: #f4f4f4;
|
12 |
-
padding: 20px;
|
13 |
-
}
|
14 |
-
.container {
|
15 |
-
max-width: 800px;
|
16 |
-
margin: 0 auto;
|
17 |
-
background: #fff;
|
18 |
-
padding: 30px;
|
19 |
-
border-radius: 10px;
|
20 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
21 |
-
}
|
22 |
-
h1 {
|
23 |
-
text-align: center;
|
24 |
-
margin-bottom: 30px;
|
25 |
-
}
|
26 |
-
.audio-section {
|
27 |
-
text-align: center;
|
28 |
-
margin-bottom: 20px;
|
29 |
-
}
|
30 |
-
input[type="file"] {
|
31 |
-
display: none;
|
32 |
-
}
|
33 |
-
.upload-btn {
|
34 |
-
background-color: #007bff;
|
35 |
-
color: white;
|
36 |
-
padding: 10px 20px;
|
37 |
-
cursor: pointer;
|
38 |
-
border-radius: 5px;
|
39 |
-
margin: 10px;
|
40 |
-
border: none;
|
41 |
-
display: inline-block;
|
42 |
-
}
|
43 |
-
.button {
|
44 |
-
background-color: #28a745;
|
45 |
-
color: white;
|
46 |
-
padding: 10px 20px;
|
47 |
-
cursor: pointer;
|
48 |
-
border: none;
|
49 |
-
border-radius: 5px;
|
50 |
-
margin-top: 20px;
|
51 |
-
display: block;
|
52 |
-
width: 100%;
|
53 |
-
font-size: 16px;
|
54 |
-
}
|
55 |
-
.button:hover {
|
56 |
-
background-color: #218838;
|
57 |
-
}
|
58 |
-
#progress-bar {
|
59 |
-
width: 0;
|
60 |
-
height: 20px;
|
61 |
-
background-color: #4caf50;
|
62 |
-
text-align: center;
|
63 |
-
line-height: 20px;
|
64 |
-
color: white;
|
65 |
-
border-radius: 5px;
|
66 |
-
display: none;
|
67 |
-
}
|
68 |
-
#progress-container {
|
69 |
-
width: 100%;
|
70 |
-
background-color: #ddd;
|
71 |
-
border-radius: 5px;
|
72 |
-
margin-top: 20px;
|
73 |
-
}
|
74 |
-
.result {
|
75 |
-
margin-top: 20px;
|
76 |
-
}
|
77 |
-
.recorder {
|
78 |
-
cursor: pointer;
|
79 |
-
background-color: #dc3545;
|
80 |
-
color: white;
|
81 |
-
padding: 10px 20px;
|
82 |
-
border-radius: 50%;
|
83 |
-
font-size: 24px;
|
84 |
-
display: inline-block;
|
85 |
-
margin-top: 20px;
|
86 |
-
}
|
87 |
-
.stop-button {
|
88 |
-
background-color: #ff5733;
|
89 |
-
color: white;
|
90 |
-
padding: 10px 20px;
|
91 |
-
cursor: pointer;
|
92 |
-
border-radius: 5px;
|
93 |
-
display: none;
|
94 |
-
margin: 10px;
|
95 |
-
}
|
96 |
-
</style>
|
97 |
-
</head>
|
98 |
-
<body>
|
99 |
-
<div class="container">
|
100 |
-
<h1>Audio Transcription and Similarity Checker</h1>
|
101 |
-
|
102 |
-
<div id="original-audio" class="audio-section">
|
103 |
-
<h2>Upload or Record Original Audio</h2>
|
104 |
-
<label class="upload-btn" for="originalFile">Choose Audio File</label>
|
105 |
-
<input type="file" id="originalFile" accept="audio/*">
|
106 |
-
<div id="originalRecorder" class="recorder">
|
107 |
-
<i class="fas fa-microphone"></i> Record
|
108 |
-
</div>
|
109 |
-
<button id="stopOriginalRecording" class="stop-button">Stop Recording</button>
|
110 |
-
</div>
|
111 |
-
|
112 |
-
<div id="user-audio" class="audio-section">
|
113 |
-
<h2>Upload or Record User Audio</h2>
|
114 |
-
<label class="upload-btn" for="userFile">Choose Audio File</label>
|
115 |
-
<input type="file" id="userFile" accept="audio/*">
|
116 |
-
<div id="userRecorder" class="recorder">
|
117 |
-
<i class="fas fa-microphone"></i> Record
|
118 |
-
</div>
|
119 |
-
<button id="stopUserRecording" class="stop-button">Stop Recording</button>
|
120 |
-
</div>
|
121 |
-
|
122 |
-
<button id="transcribeButton" class="button">Perform Transcription and Testing</button>
|
123 |
-
|
124 |
-
<div id="progress-container">
|
125 |
-
<div id="progress-bar">0%</div>
|
126 |
-
</div>
|
127 |
-
|
128 |
-
<div id="result" class="result"></div>
|
129 |
-
</div>
|
130 |
-
|
131 |
-
<script src="https://cdn.jsdelivr.net/npm/@huggingface/transformers"></script>
|
132 |
-
<script>
|
133 |
-
const MODEL_ID = "facebook/wav2vec2-large-960h"; // Sample model, change if necessary
|
134 |
-
let processor, model;
|
135 |
-
let originalAudioBlob = null;
|
136 |
-
let userAudioBlob = null;
|
137 |
-
|
138 |
-
// Load model and processor
|
139 |
-
async function loadModel() {
|
140 |
-
processor = await transformers.AutoProcessor.from_pretrained(MODEL_ID);
|
141 |
-
model = await transformers.Wav2Vec2ForCTC.from_pretrained(MODEL_ID);
|
142 |
-
}
|
143 |
-
|
144 |
-
// Simulate progress bar loading
|
145 |
-
function updateProgressBar(percentComplete) {
|
146 |
-
const progressBar = document.getElementById("progress-bar");
|
147 |
-
progressBar.style.width = percentComplete + "%";
|
148 |
-
progressBar.innerHTML = percentComplete + "%";
|
149 |
-
if (percentComplete === 100) {
|
150 |
-
setTimeout(() => {
|
151 |
-
progressBar.style.display = "none";
|
152 |
-
progressBar.style.width = "0%";
|
153 |
-
}, 500);
|
154 |
-
} else {
|
155 |
-
progressBar.style.display = "block";
|
156 |
-
}
|
157 |
-
}
|
158 |
-
|
159 |
-
async function transcribe(audioBlob) {
|
160 |
-
const arrayBuffer = await audioBlob.arrayBuffer();
|
161 |
-
const audioData = new Float32Array(arrayBuffer);
|
162 |
-
|
163 |
-
const inputValues = processor(audioData, {return_tensors: "pt", padding: true}).input_values;
|
164 |
-
const logits = await model(inputValues).logits;
|
165 |
-
const predicted_ids = logits.argmax(-1);
|
166 |
-
const transcription = processor.decode(predicted_ids, {skip_special_tokens: true});
|
167 |
-
return transcription;
|
168 |
-
}
|
169 |
-
|
170 |
-
document.getElementById("transcribeButton").addEventListener("click", async () => {
|
171 |
-
if (!originalAudioBlob && !document.getElementById("originalFile").files[0]) {
|
172 |
-
alert("Please upload or record original audio.");
|
173 |
-
return;
|
174 |
-
}
|
175 |
-
if (!userAudioBlob && !document.getElementById("userFile").files[0]) {
|
176 |
-
alert("Please upload or record user audio.");
|
177 |
-
return;
|
178 |
-
}
|
179 |
-
|
180 |
-
updateProgressBar(0);
|
181 |
-
let percentComplete = 0;
|
182 |
-
const progressInterval = setInterval(() => {
|
183 |
-
percentComplete += 10;
|
184 |
-
updateProgressBar(percentComplete);
|
185 |
-
if (percentComplete >= 100) clearInterval(progressInterval);
|
186 |
-
}, 200);
|
187 |
-
|
188 |
-
if (!originalAudioBlob) {
|
189 |
-
originalAudioBlob = document.getElementById("originalFile").files[0];
|
190 |
-
}
|
191 |
-
if (!userAudioBlob) {
|
192 |
-
userAudioBlob = document.getElementById("userFile").files[0];
|
193 |
-
}
|
194 |
-
|
195 |
-
const transcriptionOriginal = await transcribe(originalAudioBlob);
|
196 |
-
const transcriptionUser = await transcribe(userAudioBlob);
|
197 |
-
|
198 |
-
clearInterval(progressInterval);
|
199 |
-
updateProgressBar(100);
|
200 |
-
|
201 |
-
const levenshteinDistance = (a, b) => {
|
202 |
-
let dp = Array.from({length: a.length + 1}, () => Array(b.length + 1).fill(0));
|
203 |
-
for (let i = 0; i <= a.length; i++) dp[i][0] = i;
|
204 |
-
for (let j = 0; j <= b.length; j++) dp[0][j] = j;
|
205 |
-
for (let i = 1; i <= a.length; i++) {
|
206 |
-
for (let j = 1; j <= b.length; j++) {
|
207 |
-
dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1;
|
208 |
-
}
|
209 |
-
}
|
210 |
-
return dp[a.length][b.length];
|
211 |
-
};
|
212 |
-
|
213 |
-
const similarityScore = 1 - levenshteinDistance(transcriptionOriginal, transcriptionUser) / Math.max(transcriptionOriginal.length, transcriptionUser.length);
|
214 |
-
|
215 |
-
document.getElementById("result").innerHTML = `
|
216 |
-
<h2>Transcription Results</h2>
|
217 |
-
<p><strong>Original Transcription:</strong> ${transcriptionOriginal}</p>
|
218 |
-
<p><strong>User Transcription:</strong> ${transcriptionUser}</p>
|
219 |
-
<p><strong>Levenshtein Similarity Score:</strong> ${similarityScore.toFixed(2)}</p>
|
220 |
-
`;
|
221 |
-
});
|
222 |
-
|
223 |
-
// Initialize model
|
224 |
-
loadModel();
|
225 |
-
|
226 |
-
// Handle voice recording (using browser APIs)
|
227 |
-
const recordAudio = () => {
|
228 |
-
return new Promise(async resolve => {
|
229 |
-
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
230 |
-
const mediaRecorder = new MediaRecorder(stream);
|
231 |
-
const audioChunks = [];
|
232 |
-
|
233 |
-
mediaRecorder.addEventListener("dataavailable", event => {
|
234 |
-
audioChunks.push(event.data);
|
235 |
-
});
|
236 |
-
|
237 |
-
mediaRecorder.addEventListener("stop", () => {
|
238 |
-
const audioBlob = new Blob(audioChunks);
|
239 |
-
resolve(audioBlob);
|
240 |
-
});
|
241 |
-
|
242 |
-
mediaRecorder.start();
|
243 |
-
return mediaRecorder;
|
244 |
-
});
|
245 |
-
};
|
246 |
-
|
247 |
-
let originalRecorderInstance, userRecorderInstance;
|
248 |
-
|
249 |
-
document.getElementById("originalRecorder").addEventListener("click", async () => {
|
250 |
-
originalRecorderInstance = await recordAudio();
|
251 |
-
document.getElementById("stopOriginalRecording").style.display = "inline-block";
|
252 |
-
document.getElementById("originalRecorder").style.display = "none";
|
253 |
-
});
|
254 |
-
|
255 |
-
document.getElementById("stopOriginalRecording").addEventListener("click", () => {
|
256 |
-
originalRecorderInstance.stop();
|
257 |
-
originalRecorderInstance.addEventListener("stop", async () => {
|
258 |
-
originalAudioBlob = new Blob(originalRecorderInstance);
|
259 |
-
alert("Original audio recorded!");
|
260 |
-
});
|
261 |
-
document.getElementById("stopOriginalRecording").style.display = "none";
|
262 |
-
document.getElementById("originalRecorder").style.display = "inline-block";
|
263 |
-
});
|
264 |
-
|
265 |
-
document.getElementById("userRecorder").addEventListener("click", async () => {
|
266 |
-
userRecorderInstance = await recordAudio();
|
267 |
-
document.getElementById("stopUserRecording").style.display = "inline-block";
|
268 |
-
document.getElementById("userRecorder").style.display = "none";
|
269 |
-
});
|
270 |
-
|
271 |
-
document.getElementById("stopUserRecording").addEventListener("click", () => {
|
272 |
-
userRecorderInstance.stop();
|
273 |
-
userRecorderInstance.addEventListener("stop", async () => {
|
274 |
-
userAudioBlob = new Blob(userRecorderInstance);
|
275 |
-
alert("User audio recorded!");
|
276 |
-
});
|
277 |
-
document.getElementById("stopUserRecording").style.display = "none";
|
278 |
-
document.getElementById("userRecorder").style.display = "inline-block";
|
279 |
-
});
|
280 |
-
</script>
|
281 |
-
</body>
|
282 |
-
</html>
|
|
|
1 |
+
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="shortcut icon" href="/favicon.ico"><title>React App</title><link href="/static/css/main.8254a768.css" rel="stylesheet"></head><body><div id="root"></div><script type="text/javascript" src="/static/js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