Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <title>Smart Chatbot</title> | |
| <style> | |
| body { font-family: Arial, sans-serif; margin: 40px; } | |
| input, button { padding: 10px; font-size: 16px; } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Smart Chatbot 🤖</h1> | |
| <input type="text" id="userInput" placeholder="Ask something..." /> | |
| <button onclick="ask()">Ask</button> | |
| <p id="response"></p> | |
| <script> | |
| const API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-small"; | |
| const HF_TOKEN = "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"; // <-- Replace with your token | |
| async function ask() { | |
| const input = document.getElementById("userInput").value; | |
| document.getElementById("response").innerText = "Thinking..."; | |
| const response = await fetch(API_URL, { | |
| method: "POST", | |
| headers: { | |
| "Authorization": `Bearer ${HF_TOKEN}`, | |
| "Content-Type": "application/json" | |
| }, | |
| body: JSON.stringify({ | |
| "inputs": input | |
| }) | |
| }); | |
| const result = await response.json(); | |
| if (result.error) { | |
| document.getElementById("response").innerText = "Error: " + result.error; | |
| } else { | |
| document.getElementById("response").innerText = result[0].generated_text; | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> | |