Ai_project / index.html
Pro-Creator-16's picture
Update index.html
dfce86c verified
Raw History Blame Contribute Delete
5.41 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fixed Browser AI</title>
<style>
:root {
--bg: #0f172a;
--panel: #1e293b;
--text: #f8fafc;
--primary: #10b981;
--primary-hover: #059669;
--border: #334155;
}
body {
font-family: system-ui, -apple-system, sans-serif;
background-color: var(--bg);
color: var(--text);
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
box-sizing: border-box;
}
.app-card {
width: 100%;
max-width: 550px;
background: var(--panel);
padding: 30px;
border-radius: 16px;
box-shadow: 0 20px 25px -5px rgba(0,0,0,0.4);
border: 1px solid var(--border);
}
h1 { font-size: 1.6rem; margin: 0 0 8px 0; font-weight: 700; text-align: center; }
.tagline { text-align: center; color: #94a3b8; font-size: 0.9rem; margin-bottom: 24px; }
.field { margin-bottom: 18px; }
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; color: #cbd5e1; }
textarea {
width: 100%;
padding: 12px;
background: #0f172a;
border: 1px solid var(--border);
border-radius: 8px;
color: white;
font-size: 0.95rem;
box-sizing: border-box;
height: 110px;
resize: none;
}
textarea:focus { outline: 2px solid var(--primary); }
button {
width: 100%;
padding: 14px;
background: var(--primary);
color: white;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background 0.15s ease;
}
button:hover { background: var(--primary-hover); }
button:disabled { background: #475569; cursor: not-allowed; }
.response-container {
margin-top: 24px;
padding: 16px;
background: #0f172a;
border-radius: 8px;
border-left: 4px solid var(--primary);
display: none;
}
.response-text { white-space: pre-wrap; margin: 0; font-size: 0.95rem; line-height: 1.5; }
</style>
</head>
<body>
<div class="app-card">
<h1>Local Browser AI</h1>
<div class="tagline">100% Client-Side Web AI App</div>
<div class="field">
<label for="prompt">Your Query:</label>
<textarea id="prompt" placeholder="Type a sentence starter (e.g., 'Once upon a time,')"></textarea>
</div>
<!-- Bound explicitly using the unique element execution ID -->
<button id="submitBtn">Generate Response</button>
<div id="responseBox" class="response-container">
<p id="responseText" class="response-text"></p>
</div>
</div>
<script type="module">
import { pipeline, env } from 'https://jsdelivr.net';
env.allowLocalModels = false;
let generator = null;
// Attach event handler directly using addEventListener to bypass module sandbox restrictions
document.getElementById('submitBtn').addEventListener('click', async () => {
const prompt = document.getElementById('prompt').value.trim();
const btn = document.getElementById('submitBtn');
const box = document.getElementById('responseBox');
const text = document.getElementById('responseText');
if (!prompt) {
alert('Please enter a prompt starter first!');
return;
}
btn.disabled = true;
btn.innerText = 'Processing...';
box.style.display = 'block';
try {
if (!generator) {
text.innerText = 'Downloading model files directly to your browser memory... (This takes 30-60 seconds on the very first load)';
// Loads a highly compressed 0.5 Billion parameter model built explicitly for client browsers
generator = await pipeline('text-generation', 'Xenova/Qwen1.5-0.5B-Chat');
}
text.innerText = 'Thinking locally inside your browser cache...';
const output = await generator(prompt, {
max_new_tokens: 40,
temperature: 0.7,
do_sample: true
});
// FIXED: Extracted matching array index object layout correctly
if (Array.isArray(output) && output[0] && output[0].generated_text) {
text.innerText = output[0].generated_text;
} else if (output && output.generated_text) {
text.innerText = output.generated_text;
} else {
text.innerText = JSON.stringify(output, null, 2);
}
} catch (err) {
text.innerText = `Execution Error: ${err.message}\n\nPlease check if your browser version is fully updated.`;
console.error(err);
} finally {
btn.disabled = false;
btn.innerText = 'Generate Response';
}
});
</script>
</body>
</html>