Update README.md
Browse files
README.md
CHANGED
@@ -13,9 +13,130 @@ The model seems to be of the TFLite model format with the following architecture
|
|
13 |
|
14 |
|
15 |
## Run the model using Mediapipe:
|
16 |
-
|
17 |
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
## License
|
21 |
I dont own shit. Just extracted the model weights stored as a .bin file. https://policies.google.com/terms/generative-ai/use-policy
|
|
|
13 |
|
14 |
|
15 |
## Run the model using Mediapipe:
|
16 |
+
Instructions from here: https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/llm_inference/js
|
17 |
|
18 |
+
In a directory, make two files:
|
19 |
|
20 |
+
`index.html`:
|
21 |
+
```html
|
22 |
+
<!-- Copyright 2024 The MediaPipe Authors.
|
23 |
+
|
24 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
25 |
+
you may not use this file except in compliance with the License.
|
26 |
+
You may obtain a copy of the License at
|
27 |
+
|
28 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
29 |
+
|
30 |
+
Unless required by applicable law or agreed to in writing, software
|
31 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
32 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
33 |
+
See the License for the specific language governing permissions and
|
34 |
+
limitations under the License. -->
|
35 |
+
|
36 |
+
<!doctype html>
|
37 |
+
<html lang="en">
|
38 |
+
<head>
|
39 |
+
<title>LLM Inference Web Demo</title>
|
40 |
+
</head>
|
41 |
+
<body>
|
42 |
+
Input:<br />
|
43 |
+
<textarea id="input" style="height: 300px; width: 600px"></textarea><br />
|
44 |
+
<input type="button" id="submit" value="Get Response" disabled /><br />
|
45 |
+
<br />
|
46 |
+
Result:<br />
|
47 |
+
<textarea id="output" style="height: 300px; width: 600px"></textarea>
|
48 |
+
<script type="module" src="index.js"></script>
|
49 |
+
</body>
|
50 |
+
</html>
|
51 |
+
```
|
52 |
+
|
53 |
+
`index.js`(Replace line no. 23 to the path to the .bin file):
|
54 |
+
```js
|
55 |
+
// Copyright 2024 The MediaPipe Authors.
|
56 |
+
|
57 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
58 |
+
// you may not use this file except in compliance with the License.
|
59 |
+
// You may obtain a copy of the License at
|
60 |
+
|
61 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
62 |
+
|
63 |
+
// Unless required by applicable law or agreed to in writing, software
|
64 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
65 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
66 |
+
// See the License for the specific language governing permissions and
|
67 |
+
// limitations under the License.
|
68 |
+
|
69 |
+
// ---------------------------------------------------------------------------------------- //
|
70 |
+
|
71 |
+
import {FilesetResolver, LlmInference} from 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai';
|
72 |
+
|
73 |
+
const input = document.getElementById('input');
|
74 |
+
const output = document.getElementById('output');
|
75 |
+
const submit = document.getElementById('submit');
|
76 |
+
|
77 |
+
const modelFileName = 'weights.bin'; /* PATH TO MODEL .bin */
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Display newly generated partial results to the output text box.
|
81 |
+
*/
|
82 |
+
function displayPartialResults(partialResults, complete) {
|
83 |
+
output.textContent += partialResults;
|
84 |
+
|
85 |
+
if (complete) {
|
86 |
+
if (!output.textContent) {
|
87 |
+
output.textContent = 'Result is empty';
|
88 |
+
}
|
89 |
+
submit.disabled = false;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Main function to run LLM Inference.
|
95 |
+
*/
|
96 |
+
async function runDemo() {
|
97 |
+
const genaiFileset = await FilesetResolver.forGenAiTasks(
|
98 |
+
'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-genai/wasm');
|
99 |
+
let llmInference;
|
100 |
+
|
101 |
+
submit.onclick = () => {
|
102 |
+
output.textContent = '';
|
103 |
+
submit.disabled = true;
|
104 |
+
llmInference.generateResponse(input.value, displayPartialResults);
|
105 |
+
};
|
106 |
+
|
107 |
+
submit.value = 'Loading the model...'
|
108 |
+
LlmInference
|
109 |
+
.createFromOptions(genaiFileset, {
|
110 |
+
baseOptions: {modelAssetPath: modelFileName},
|
111 |
+
// maxTokens: 512, // The maximum number of tokens (input tokens + output
|
112 |
+
// // tokens) the model handles.
|
113 |
+
// randomSeed: 1, // The random seed used during text generation.
|
114 |
+
// topK: 1, // The number of tokens the model considers at each step of
|
115 |
+
// // generation. Limits predictions to the top k most-probable
|
116 |
+
// // tokens. Setting randomSeed is required for this to make
|
117 |
+
// // effects.
|
118 |
+
// temperature:
|
119 |
+
// 1.0, // The amount of randomness introduced during generation.
|
120 |
+
// // Setting randomSeed is required for this to make effects.
|
121 |
+
})
|
122 |
+
.then(llm => {
|
123 |
+
llmInference = llm;
|
124 |
+
submit.disabled = false;
|
125 |
+
submit.value = 'Get Response'
|
126 |
+
})
|
127 |
+
.catch(() => {
|
128 |
+
alert('Failed to initialize the task.');
|
129 |
+
});
|
130 |
+
}
|
131 |
+
|
132 |
+
runDemo();
|
133 |
+
```
|
134 |
+
## Run using:
|
135 |
+
`python3 -m http.server 8000` in the same directory (or python -m SimpleHTTPServer 8000 for older python versions).
|
136 |
+
|
137 |
+
Finally,
|
138 |
+
|
139 |
+
`Open localhost:8000 in Chrome`
|
140 |
|
141 |
## License
|
142 |
I dont own shit. Just extracted the model weights stored as a .bin file. https://policies.google.com/terms/generative-ai/use-policy
|