Spaces:
Runtime error
Runtime error
File size: 1,936 Bytes
aee0a95 |
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 |
<!DOCTYPE html>
<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> |