Pro-Creator-16 commited on
Commit
dfce86c
·
verified ·
1 Parent(s): 0e9525a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +14 -15
index.html CHANGED
@@ -80,32 +80,29 @@
80
 
81
  <div class="app-card">
82
  <h1>Local Browser AI</h1>
83
- <div class="tagline">100% Client-Side Generation (No Keys, No Network Blocks)</div>
84
 
85
  <div class="field">
86
  <label for="prompt">Your Query:</label>
87
  <textarea id="prompt" placeholder="Type a sentence starter (e.g., 'Once upon a time,')"></textarea>
88
  </div>
89
 
90
- <!-- The button links directly to our globally mapped window function -->
91
- <button id="submitBtn" onclick="window.runLocalAI()">Generate Response</button>
92
 
93
  <div id="responseBox" class="response-container">
94
  <p id="responseText" class="response-text"></p>
95
  </div>
96
  </div>
97
 
98
- <!-- Load Transformers.js via module scripts -->
99
  <script type="module">
100
  import { pipeline, env } from 'https://jsdelivr.net';
101
 
102
- // Configures safe browser performance defaults
103
  env.allowLocalModels = false;
104
-
105
  let generator = null;
106
 
107
- // FIX: Bind the execution directly to the window so the HTML button can trigger it
108
- window.runLocalAI = async function() {
109
  const prompt = document.getElementById('prompt').value.trim();
110
  const btn = document.getElementById('submitBtn');
111
  const box = document.getElementById('responseBox');
@@ -122,12 +119,12 @@
122
 
123
  try {
124
  if (!generator) {
125
- text.innerText = 'Downloading small language model to your browser tab (This takes up to a minute on first load)...';
126
- // Loads an ultra-lightweight 0.5B parameters model designed for basic browser tasks
127
  generator = await pipeline('text-generation', 'Xenova/Qwen1.5-0.5B-Chat');
128
  }
129
 
130
- text.innerText = 'Generating thoughts locally inside your browser memory...';
131
 
132
  const output = await generator(prompt, {
133
  max_new_tokens: 40,
@@ -135,21 +132,23 @@
135
  do_sample: true
136
  });
137
 
138
- // Extract text from standard Transformers.js object format
139
- if (output && output[0] && output[0].generated_text) {
140
  text.innerText = output[0].generated_text;
 
 
141
  } else {
142
  text.innerText = JSON.stringify(output, null, 2);
143
  }
144
 
145
  } catch (err) {
146
- text.innerText = `Error: ${err.message}\n\nTip: If loading fails, ensure your browser is fully updated and WebGL/WebGPU is enabled.`;
147
  console.error(err);
148
  } finally {
149
  btn.disabled = false;
150
  btn.innerText = 'Generate Response';
151
  }
152
- }
153
  </script>
154
 
155
  </body>
 
80
 
81
  <div class="app-card">
82
  <h1>Local Browser AI</h1>
83
+ <div class="tagline">100% Client-Side Web AI App</div>
84
 
85
  <div class="field">
86
  <label for="prompt">Your Query:</label>
87
  <textarea id="prompt" placeholder="Type a sentence starter (e.g., 'Once upon a time,')"></textarea>
88
  </div>
89
 
90
+ <!-- Bound explicitly using the unique element execution ID -->
91
+ <button id="submitBtn">Generate Response</button>
92
 
93
  <div id="responseBox" class="response-container">
94
  <p id="responseText" class="response-text"></p>
95
  </div>
96
  </div>
97
 
 
98
  <script type="module">
99
  import { pipeline, env } from 'https://jsdelivr.net';
100
 
 
101
  env.allowLocalModels = false;
 
102
  let generator = null;
103
 
104
+ // Attach event handler directly using addEventListener to bypass module sandbox restrictions
105
+ document.getElementById('submitBtn').addEventListener('click', async () => {
106
  const prompt = document.getElementById('prompt').value.trim();
107
  const btn = document.getElementById('submitBtn');
108
  const box = document.getElementById('responseBox');
 
119
 
120
  try {
121
  if (!generator) {
122
+ text.innerText = 'Downloading model files directly to your browser memory... (This takes 30-60 seconds on the very first load)';
123
+ // Loads a highly compressed 0.5 Billion parameter model built explicitly for client browsers
124
  generator = await pipeline('text-generation', 'Xenova/Qwen1.5-0.5B-Chat');
125
  }
126
 
127
+ text.innerText = 'Thinking locally inside your browser cache...';
128
 
129
  const output = await generator(prompt, {
130
  max_new_tokens: 40,
 
132
  do_sample: true
133
  });
134
 
135
+ // FIXED: Extracted matching array index object layout correctly
136
+ if (Array.isArray(output) && output[0] && output[0].generated_text) {
137
  text.innerText = output[0].generated_text;
138
+ } else if (output && output.generated_text) {
139
+ text.innerText = output.generated_text;
140
  } else {
141
  text.innerText = JSON.stringify(output, null, 2);
142
  }
143
 
144
  } catch (err) {
145
+ text.innerText = `Execution Error: ${err.message}\n\nPlease check if your browser version is fully updated.`;
146
  console.error(err);
147
  } finally {
148
  btn.disabled = false;
149
  btn.innerText = 'Generate Response';
150
  }
151
+ });
152
  </script>
153
 
154
  </body>