File size: 2,963 Bytes
b0a27ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83afe32
b0a27ea
 
 
 
 
 
 
73d70b7
 
 
 
 
 
 
 
d8ba489
73d70b7
 
 
 
d8ba489
b0a27ea
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!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>