Create Quotes
#5
by Devil-user087 - opened
Quotes
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
| 6 |
+
<title>AI Quote Generator (Offline)</title>
|
| 7 |
+
<script src="https://cdn.jsdelivr.net/npm/@xenova/transformers@2.6.0"></script>
|
| 8 |
+
<style>
|
| 9 |
+
body { font-family: Arial, sans-serif; text-align: center; padding: 30px; background: #f4f4f4; }
|
| 10 |
+
input, button { padding: 10px; font-size: 16px; }
|
| 11 |
+
#output { margin-top: 20px; padding: 15px; background: white; border-radius: 10px; }
|
| 12 |
+
</style>
|
| 13 |
+
</head>
|
| 14 |
+
<body>
|
| 15 |
+
<h1>🧠 AI Quote Generator</h1>
|
| 16 |
+
<p>Runs 100% in your browser using Transformers.js</p>
|
| 17 |
+
|
| 18 |
+
<input type="text" id="topic" placeholder="Enter a topic (love, success...)" />
|
| 19 |
+
<button onclick="generate()">Generate Quote</button>
|
| 20 |
+
|
| 21 |
+
<div id="loading" style="display:none; color:green;">Loading model, please wait...</div>
|
| 22 |
+
<div id="output"></div>
|
| 23 |
+
|
| 24 |
+
<script>
|
| 25 |
+
let pipeline, loaded = false;
|
| 26 |
+
|
| 27 |
+
async function loadModel() {
|
| 28 |
+
document.getElementById("loading").style.display = "block";
|
| 29 |
+
pipeline = await window.transformers.pipeline("text-generation", "Xenova/distilgpt2");
|
| 30 |
+
loaded = true;
|
| 31 |
+
document.getElementById("loading").style.display = "none";
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
async function generate() {
|
| 35 |
+
if (!loaded) {
|
| 36 |
+
alert("Please wait, model is still loading...");
|
| 37 |
+
return;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
const topic = document.getElementById("topic").value.trim();
|
| 41 |
+
if (!topic) {
|
| 42 |
+
alert("Please enter a topic.");
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
document.getElementById("output").innerText = "Generating...";
|
| 47 |
+
const result = await pipeline(`Quote about ${topic}:`, {
|
| 48 |
+
max_new_tokens: 50,
|
| 49 |
+
temperature: 0.9,
|
| 50 |
+
top_k: 50
|
| 51 |
+
});
|
| 52 |
+
const text = result[0].generated_text.replace(/Quote about .*?:/, "").trim();
|
| 53 |
+
document.getElementById("output").innerText = "“" + text + "”";
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
loadModel();
|
| 57 |
+
</script>
|
| 58 |
+
</body>
|
| 59 |
+
</html>
|