<!-- Copyright 2024 The MediaPipe Authors.Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License. --><!doctype html><htmllang="en"><head><title>LLM Inference Web Demo</title></head><body>
Input:<br /><textareaid="input"style="height: 300px; width: 600px"></textarea><br /><inputtype="button"id="submit"value="Get Response"disabled /><br /><br />
Result:<br /><textareaid="output"style="height: 300px; width: 600px"></textarea><scripttype="module"src="index.js"></script></body></html>
index.js
(Replace line no. 23 to the path to the .bin file):
// Copyright 2024 The MediaPipe Authors.// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// ---------------------------------------------------------------------------------------- //import {FilesetResolver, LlmInference} from'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai';
const input = document.getElementById('input');
const output = document.getElementById('output');
const submit = document.getElementById('submit');
const modelFileName = 'weights.bin'; /* PATH TO MODEL .bin *//** * Display newly generated partial results to the output text box. */functiondisplayPartialResults(partialResults, complete) {
output.textContent += partialResults;
if (complete) {
if (!output.textContent) {
output.textContent = 'Result is empty';
}
submit.disabled = false;
}
}
/** * Main function to run LLM Inference. */asyncfunctionrunDemo() {
const genaiFileset = awaitFilesetResolver.forGenAiTasks(
'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai/wasm');
let llmInference;
submit.onclick = () => {
output.textContent = '';
submit.disabled = true;
llmInference.generateResponse(input.value, displayPartialResults);
};
submit.value = 'Loading the model...'LlmInference
.createFromOptions(genaiFileset, {
baseOptions: {modelAssetPath: modelFileName},
// maxTokens: 512, // The maximum number of tokens (input tokens + output// // tokens) the model handles.// randomSeed: 1, // The random seed used during text generation.// topK: 1, // The number of tokens the model considers at each step of// // generation. Limits predictions to the top k most-probable// // tokens. Setting randomSeed is required for this to make// // effects.// temperature:// 1.0, // The amount of randomness introduced during generation.// // Setting randomSeed is required for this to make effects.
})
.then(llm => {
llmInference = llm;
submit.disabled = false;
submit.value = 'Get Response'
})
.catch(() => {
alert('Failed to initialize the task.');
});
}
runDemo();
Run using:
python3 -m http.server 8000
in the same directory (or python -m SimpleHTTPServer 8000 for older python versions).
More Information About Gemini-Nano huggingface.co Model
Gemini-Nano huggingface.co
Gemini-Nano huggingface.co is an AI model on huggingface.co that provides Gemini-Nano's model effect (), which can be used instantly with this eadx Gemini-Nano model. huggingface.co supports a free trial of the Gemini-Nano model, and also provides paid use of the Gemini-Nano. Support call Gemini-Nano model through api, including Node.js, Python, http.
Gemini-Nano huggingface.co is an online trial and call api platform, which integrates Gemini-Nano's modeling effects, including api services, and provides a free online trial of Gemini-Nano, you can try Gemini-Nano online for free by clicking the link below.
eadx Gemini-Nano online free url in huggingface.co:
Gemini-Nano is an open source model from GitHub that offers a free installation service, and any user can find Gemini-Nano on GitHub to install. At the same time, huggingface.co provides the effect of Gemini-Nano install, users can directly use Gemini-Nano installed effect in huggingface.co for debugging and trial. It also supports api for free installation.