Spaces:
Sleeping
Sleeping
File size: 2,446 Bytes
d1d6660 d6e4f49 d1d6660 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AI Comment Generator</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
font-family: "Inter", sans-serif;
}
</style>
</head>
<body class="bg-gray-950 text-gray-50 min-h-screen flex items-center justify-center p-4">
<div class="w-full max-w-xl bg-gray-900 rounded-xl p-8 shadow-2xl border border-gray-800">
<h1 class="text-3xl font-bold mb-6 text-center text-gradient">
AI Comment Generator
</h1>
<form id="promptForm" class="space-y-4">
<textarea
id="prompt"
name="prompt"
class="w-full p-4 rounded-md bg-gray-800 border border-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-600 text-gray-100 placeholder-gray-400"
placeholder="Enter your prompt..."
rows="5"
></textarea>
<button
type="submit"
class="w-full py-3 bg-blue-600 hover:bg-blue-500 rounded-md font-semibold text-white transition-colors"
>
Generate
</button>
</form>
<div
id="result"
class="mt-6 p-4 rounded-md bg-gray-800 border border-gray-700 text-gray-100 min-h-[100px] whitespace-pre-wrap"
></div>
</div>
<script>
const form = document.getElementById('promptForm');
const resultDiv = document.getElementById('result');
form.addEventListener('submit', async (e) => {
e.preventDefault();
resultDiv.textContent = 'Generating...';
const prompt = document.getElementById('prompt').value;
const res = await fetch('/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ prompt })
});
if (!res.body) {
resultDiv.textContent = 'No streaming supported.';
return;
}
const reader = res.body.getReader();
const decoder = new TextDecoder();
resultDiv.textContent = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value, { stream: true });
resultDiv.textContent += chunk;
}
});
</script>
</body>
</html> |