proandosi / templates /chat.html
jorgencio's picture
arreglando error 422 creol
d8ba489
<!DOCTYPE html>
<html lang="en">
<head>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f4f7fa;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 20px;
}
.chat-bubbles {
width: 100%;
max-width: 600px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 20px;
margin-bottom: 20px;
overflow-y: auto;
max-height: 70vh;
}
.message {
display: flex;
align-items: flex-start;
margin-bottom: 15px;
}
.message img {
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 10px;
}
.chat-bubble {
background-color: #f0f1f6;
padding: 10px 15px;
border-radius: 15px;
max-width: 80%;
font-size: 14px;
color: #333;
}
.message.user .chat-bubble {
background-color: #a2cffe;
margin-left: auto;
}
.message.character .chat-bubble {
background-color: #e8e8e8;
}
#chat-form {
display: flex;
justify-content: space-between;
width: 100%;
max-width: 600px;
}
#chat-form input {
width: 85%;
padding: 10px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 20px;
margin-right: 10px;
}
#chat-form button {
width: 10%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 20px;
cursor: pointer;
}
#chat-form button:hover {
background-color: #45a049;
}
@media screen and (max-width: 600px) {
#chat-form input {
width: 75%;
}
#chat-form button {
width: 20%;
}
}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="chat-bubbles">
{% for message in messages %}
<div class="message {{ message.type }}">
<img src="/static/{{ message.image }}" alt="Profile">
<div class="chat-bubble">
{{ message.text }}
</div>
</div>
{% endfor %}
</div>
<form id="chat-form" method="POST">
<input type="text" id="user-input" name="user_input" placeholder="Type your message..." required>
<button type="submit">Send</button>
</form>
<script>
document.getElementById("chat-form").addEventListener("submit", async function(e) {
e.preventDefault();
const userInput = document.getElementById("user-input").value;
const response = await fetch(`/personajes/{{ character_name }}/chat`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user_input: userInput })
});
const data = await response.json();
console.log(data.response);
});
</script>
</body>
</html>