Skip to content

Commit

Permalink
Merge pull request #123 from ajinkyapandetekdi/all-2.0-offline
Browse files Browse the repository at this point in the history
issueid #223924 fix: whisper model is not loading properly in offline-model
  • Loading branch information
gouravmore authored Jul 26, 2024
2 parents 81e7ba0 + bc987f3 commit 4923e4e
Showing 1 changed file with 5 additions and 45 deletions.
50 changes: 5 additions & 45 deletions src/components/Assesment/Assesment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,48 +151,6 @@ export const LanguageModal = ({
});
};

// Function to load model in whisper cpp module
const loadModelWhisper = async (modelName) => {
try {
window.whisperModule.FS_unlink("whisper.bin");
} catch (e) {
console.log(e)
}
try {
let transaction;
let store;
let request;
try {
transaction = await db.transaction(["models"], "readonly");
store = transaction.objectStore("models");
request = await store.get(modelName);
} catch (error) {
console.error("Error accessing IndexedDB:", error);
return;
}

request.onsuccess = async () => {
const modelData = request.result;
let storeResponse = await window.whisperModule.FS_createDataFile(
"/",
"whisper.bin",
modelData,
true,
true
);
setTimeout(console.log(window.whisperModule.init("whisper.bin")), 5000);
};

request.onerror = (err) => {
console.error(`Error to get model data: ${err}`);
};

console.log(`Stored model in whisper cpp memory`);
} catch (error) {
console.error("Error storing model in IndexedDB:", error);
}
};

// Function to load model
const loadModel = async () => {
setLoading(true);
Expand All @@ -208,7 +166,6 @@ export const LanguageModal = ({
console.log(`Model ${modelName} is already stored in IndexedDB`);
return;
}
await loadModelWhisper(modelName);
} catch (error) {
console.log(error.message);
} finally {
Expand Down Expand Up @@ -852,6 +809,7 @@ const Assesment = ({ discoverStart }) => {
const loadModelWhisper = async (modelName) => {
try {
window.whisperModule.FS_unlink("whisper.bin");
await window.whisperModule.free(1)
} catch (e) {
console.log(e)
}
Expand Down Expand Up @@ -945,7 +903,6 @@ const Assesment = ({ discoverStart }) => {
} else {
console.log(`Model ${modelName} is already stored in IndexedDB`);
}
await loadModelWhisper(modelName);
} catch (error) {
console.log(error.message);
} finally {
Expand Down Expand Up @@ -978,6 +935,7 @@ const Assesment = ({ discoverStart }) => {
};

const handleRedirect = async () => {
if(localStorage.getItem('isOfflineModel') === 'true'){
const modelName = "en-model";
await openDB();
const stored = await isModelStored(modelName);
Expand All @@ -986,9 +944,11 @@ const Assesment = ({ discoverStart }) => {
}
else{
alert(`you have to download en-offline model`)
loadModel();
await loadModel();
return;
}
await loadModelWhisper(modelName);
}
const profileName = getLocalData("profileName");
if (!username && !profileName && !virtualId && level === 0) {
// alert("please add username in query param");
Expand Down

0 comments on commit 4923e4e

Please sign in to comment.