Spaces:
Running
Running
Update index.html
Browse files- index.html +113 -23
index.html
CHANGED
|
@@ -1,29 +1,119 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
-
|
| 4 |
<head>
|
| 5 |
-
<meta charset="UTF-8"
|
| 6 |
-
<
|
| 7 |
-
|
| 8 |
-
<
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
</head>
|
| 11 |
-
|
| 12 |
<body>
|
| 13 |
-
<
|
| 14 |
-
|
| 15 |
-
<
|
| 16 |
-
<
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 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 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: Arial, sans-serif;
|
| 10 |
+
background-color: #f4f4f4;
|
| 11 |
+
padding: 20px;
|
| 12 |
+
}
|
| 13 |
+
.container {
|
| 14 |
+
max-width: 700px;
|
| 15 |
+
margin: 0 auto;
|
| 16 |
+
background: #fff;
|
| 17 |
+
padding: 20px;
|
| 18 |
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
| 19 |
+
}
|
| 20 |
+
h1 {
|
| 21 |
+
text-align: center;
|
| 22 |
+
}
|
| 23 |
+
.button {
|
| 24 |
+
background-color: #e8b62c;
|
| 25 |
+
color: white;
|
| 26 |
+
padding: 10px 20px;
|
| 27 |
+
text-align: center;
|
| 28 |
+
cursor: pointer;
|
| 29 |
+
border: none;
|
| 30 |
+
margin-top: 10px;
|
| 31 |
+
display: block;
|
| 32 |
+
width: 100%;
|
| 33 |
+
}
|
| 34 |
+
.audio-upload {
|
| 35 |
+
margin-top: 20px;
|
| 36 |
+
text-align: center;
|
| 37 |
+
}
|
| 38 |
+
.result {
|
| 39 |
+
margin-top: 20px;
|
| 40 |
+
}
|
| 41 |
+
</style>
|
| 42 |
</head>
|
|
|
|
| 43 |
<body>
|
| 44 |
+
<div class="container">
|
| 45 |
+
<h1>Audio Transcription and Similarity Checker</h1>
|
| 46 |
+
<div id="original-audio" class="audio-upload">
|
| 47 |
+
<h2>Upload Original Audio</h2>
|
| 48 |
+
<input type="file" id="originalFile" accept="audio/*">
|
| 49 |
+
</div>
|
| 50 |
+
|
| 51 |
+
<div id="user-audio" class="audio-upload">
|
| 52 |
+
<h2>Upload User Audio</h2>
|
| 53 |
+
<input type="file" id="userFile" accept="audio/*">
|
| 54 |
+
</div>
|
| 55 |
+
|
| 56 |
+
<button id="transcribeButton" class="button">Perform Transcription and Testing</button>
|
| 57 |
+
|
| 58 |
+
<div id="result" class="result"></div>
|
| 59 |
+
</div>
|
| 60 |
+
|
| 61 |
+
<script src="https://cdn.jsdelivr.net/npm/@huggingface/transformers"></script>
|
| 62 |
+
<script>
|
| 63 |
+
const MODEL_ID = "facebook/wav2vec2-large-960h"; // Sample model, change if necessary
|
| 64 |
+
let processor, model;
|
| 65 |
|
| 66 |
+
// Load model and processor
|
| 67 |
+
async function loadModel() {
|
| 68 |
+
processor = await transformers.AutoProcessor.from_pretrained(MODEL_ID);
|
| 69 |
+
model = await transformers.Wav2Vec2ForCTC.from_pretrained(MODEL_ID);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
async function transcribe(audioFile) {
|
| 73 |
+
const arrayBuffer = await audioFile.arrayBuffer();
|
| 74 |
+
const audioData = new Float32Array(arrayBuffer);
|
| 75 |
+
|
| 76 |
+
const inputValues = processor(audioData, {return_tensors: "pt", padding: true}).input_values;
|
| 77 |
+
const logits = await model(inputValues).logits;
|
| 78 |
+
const predicted_ids = logits.argmax(-1);
|
| 79 |
+
const transcription = processor.decode(predicted_ids, {skip_special_tokens: true});
|
| 80 |
+
return transcription;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
document.getElementById("transcribeButton").addEventListener("click", async () => {
|
| 84 |
+
const originalFile = document.getElementById("originalFile").files[0];
|
| 85 |
+
const userFile = document.getElementById("userFile").files[0];
|
| 86 |
+
|
| 87 |
+
if (originalFile && userFile) {
|
| 88 |
+
const transcriptionOriginal = await transcribe(originalFile);
|
| 89 |
+
const transcriptionUser = await transcribe(userFile);
|
| 90 |
+
|
| 91 |
+
const levenshteinDistance = (a, b) => {
|
| 92 |
+
let dp = Array.from({length: a.length + 1}, () => Array(b.length + 1).fill(0));
|
| 93 |
+
for (let i = 0; i <= a.length; i++) dp[i][0] = i;
|
| 94 |
+
for (let j = 0; j <= b.length; j++) dp[0][j] = j;
|
| 95 |
+
for (let i = 1; i <= a.length; i++) {
|
| 96 |
+
for (let j = 1; j <= b.length; j++) {
|
| 97 |
+
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;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
return dp[a.length][b.length];
|
| 101 |
+
};
|
| 102 |
+
|
| 103 |
+
const similarityScore = 1 - levenshteinDistance(transcriptionOriginal, transcriptionUser) / Math.max(transcriptionOriginal.length, transcriptionUser.length);
|
| 104 |
+
|
| 105 |
+
document.getElementById("result").innerHTML = `
|
| 106 |
+
<h2>Transcription Results</h2>
|
| 107 |
+
<p><strong>Original Transcription:</strong> ${transcriptionOriginal}</p>
|
| 108 |
+
<p><strong>User Transcription:</strong> ${transcriptionUser}</p>
|
| 109 |
+
<p><strong>Levenshtein Similarity Score:</strong> ${similarityScore.toFixed(2)}</p>
|
| 110 |
+
`;
|
| 111 |
+
} else {
|
| 112 |
+
alert("Please upload both audio files.");
|
| 113 |
+
}
|
| 114 |
+
});
|
| 115 |
+
|
| 116 |
+
loadModel();
|
| 117 |
+
</script>
|
| 118 |
+
</body>
|
| 119 |
+
</html>
|