muzammil-eds commited on
Commit
9997b92
·
verified ·
1 Parent(s): 2b5efb0

Update index.html

Browse files
Files changed (1) hide show
  1. 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
- <link rel="stylesheet" href="style.css" />
7
-
8
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
- <title>Transformers.js - Object Detection</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  </head>
11
-
12
  <body>
13
- <h1>Object Detection w/ 🤗 Transformers.js</h1>
14
- <label id="container" for="upload">
15
- <svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
16
- <path fill="#000"
17
- d="M3.5 24.3a3 3 0 0 1-1.9-.8c-.5-.5-.8-1.2-.8-1.9V2.9c0-.7.3-1.3.8-1.9.6-.5 1.2-.7 2-.7h18.6c.7 0 1.3.2 1.9.7.5.6.7 1.2.7 2v18.6c0 .7-.2 1.4-.7 1.9a3 3 0 0 1-2 .8H3.6Zm0-2.7h18.7V2.9H3.5v18.7Zm2.7-2.7h13.3c.3 0 .5 0 .6-.3v-.7l-3.7-5a.6.6 0 0 0-.6-.2c-.2 0-.4 0-.5.3l-3.5 4.6-2.4-3.3a.6.6 0 0 0-.6-.3c-.2 0-.4.1-.5.3l-2.7 3.6c-.1.2-.2.4 0 .7.1.2.3.3.6.3Z">
18
- </path>
19
- </svg>
20
- Click to upload image
21
- <label id="example">(or try example)</label>
22
- </label>
23
- <label id="status">Loading model...</label>
24
- <input id="upload" type="file" accept="image/*" />
25
-
26
- <script src="index.js" type="module"></script>
27
- </body>
 
 
 
 
 
 
28
 
29
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>