|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8" /> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
|
<title>AI Quote Generator (Offline)</title> |
|
<script src="https://cdn.jsdelivr.net/npm/@xenova/[email protected]"></script> |
|
<style> |
|
body { font-family: Arial, sans-serif; text-align: center; padding: 30px; background: #f4f4f4; } |
|
input, button { padding: 10px; font-size: 16px; } |
|
#output { margin-top: 20px; padding: 15px; background: white; border-radius: 10px; } |
|
</style> |
|
</head> |
|
<body> |
|
<h1>🧠 AI Quote Generator</h1> |
|
<p>Runs 100% in your browser using Transformers.js</p> |
|
|
|
<input type="text" id="topic" placeholder="Enter a topic (love, success...)" /> |
|
<button onclick="generate()">Generate Quote</button> |
|
|
|
<div id="loading" style="display:none; color:green;">Loading model, please wait...</div> |
|
<div id="output"></div> |
|
|
|
<script> |
|
let pipeline, loaded = false; |
|
|
|
async function loadModel() { |
|
document.getElementById("loading").style.display = "block"; |
|
pipeline = await window.transformers.pipeline("text-generation", "Xenova/distilgpt2"); |
|
loaded = true; |
|
document.getElementById("loading").style.display = "none"; |
|
} |
|
|
|
async function generate() { |
|
if (!loaded) { |
|
alert("Please wait, model is still loading..."); |
|
return; |
|
} |
|
|
|
const topic = document.getElementById("topic").value.trim(); |
|
if (!topic) { |
|
alert("Please enter a topic."); |
|
return; |
|
} |
|
|
|
document.getElementById("output").innerText = "Generating..."; |
|
const result = await pipeline(`Quote about ${topic}:`, { |
|
max_new_tokens: 50, |
|
temperature: 0.9, |
|
top_k: 50 |
|
}); |
|
const text = result[0].generated_text.replace(/Quote about .*?:/, "").trim(); |
|
document.getElementById("output").innerText = "“" + text + "”"; |
|
} |
|
|
|
loadModel(); |
|
</script> |
|
</body> |
|
</html> |
|
|