Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified chrome extension #557

Merged
merged 6 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
updated chrome extension progress bar
  • Loading branch information
AMKCode authored and AMKCode committed Aug 11, 2024
commit 80b9874ca9069cc575b90ccb7cae34ab803d801e
2 changes: 1 addition & 1 deletion examples/chrome-extension/src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
/>
</head>
<body>
<p id="init-label">Initializing model...</p>
<div id="loadingContainer"></div>

<div class="input-container form-group">
<input
type="search"
Expand Down
21 changes: 16 additions & 5 deletions examples/chrome-extension/src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import {
} from "@mlc-ai/web-llm";
import { ProgressBar, Line } from "progressbar.js";

// modified setLabel to not throw error
function setLabel(id: string, text: string) {
const label = document.getElementById(id);
if (label != null) {
label.innerText = text;
}
}

const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

const queryInput = document.getElementById("query-input")!;
Expand All @@ -37,7 +45,7 @@ const progressBar: ProgressBar = new Line("#loadingContainer", {
});

const initProgressCallback = (report: InitProgressReport) => {
console.log(report.text, report.progress);
setLabel("init-label", report.text);
progressBar.animate(report.progress, {
duration: 50,
});
Expand All @@ -47,7 +55,8 @@ const initProgressCallback = (report: InitProgressReport) => {
};

// const selectedModel = "TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC-1k";
const selectedModel = "Mistral-7B-Instruct-v0.2-q4f16_1-MLC";
// const selectedModel = "Mistral-7B-Instruct-v0.2-q4f16_1-MLC";
const selectedModel = "Qwen2-0.5B-Instruct-q4f16_1-MLC";
const engine: MLCEngineInterface = await CreateMLCEngine(selectedModel, {
initProgressCallback: initProgressCallback,
});
Expand All @@ -59,11 +68,13 @@ function enableInputs() {
if (isLoadingParams) {
sleep(500);
(<HTMLButtonElement>submitButton).disabled = false;
const loadingBarContainer = document.getElementById("loadingContainer")!;
loadingBarContainer.remove();
queryInput.focus();
isLoadingParams = false;
}
const initLabel = document.getElementById("init-label");
initLabel?.remove();
const loadingBarContainer = document.getElementById("loadingContainer")!;
loadingBarContainer?.remove();
queryInput.focus();
}

// Disable submit button if input field is empty
Expand Down