Spaces:
Sleeping
Sleeping
| <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> |