Spaces:
Runtime error
Runtime error
<html lang="ru"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Чат с моделью Hugging Face</title> | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> | |
</head> | |
<body> | |
<div class="container mt-5"> | |
<h1>Чат с моделью Hugging Face</h1> | |
<div id="chat" class="mb-3"> | |
<!-- Сообщения будут добавляться сюда --> | |
</div> | |
<div class="input-group mb-3"> | |
<input type="text" id="user-input" class="form-control" placeholder="Напишите сообщение..."> | |
<button class="btn btn-primary" onclick="sendMessage()">Отправить</button> | |
</div> | |
</div> | |
<script> | |
async function sendMessage() { | |
const userInput = document.getElementById('user-input').value; | |
const chatDiv = document.getElementById('chat'); | |
// Добавляем сообщение пользователя | |
chatDiv.innerHTML += `<div class="alert alert-primary" role="alert">${userInput}</div>`; | |
// Отправляем сообщение на сервер | |
const response = await fetch('/chat', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ message: userInput }) | |
}); | |
const data = await response.json(); | |
const reply = data.reply; | |
// Добавляем ответ модели | |
chatDiv.innerHTML += `<div class="alert alert-secondary" role="alert">${reply}</div>`; | |
// Очищаем поле ввода | |
document.getElementById('user-input').value = ''; | |
} | |
</script> | |
</body> | |
</html> |