File size: 2,960 Bytes
25ab034
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hugging Face Chat UI</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: linear-gradient(to bottom, #111, #333);
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .chat-container {
            background: #6B7280;
            color: #FFD21E;
            width: 400px;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .chat-container input {
            width: calc(100% - 70px);
            padding: 10px;
            border: 1px solid #FFD21E;
            border-radius: 20px 0 0 20px;
        }

        .chat-container button {
            width: 70px;
            padding: 10px;
            border: none;
            background: #FF9D00;
            color: #111;
            border-radius: 0 20px 20px 0;
            cursor: pointer;
        }

        .chat-message {
            margin: 10px 0;
            padding: 10px;
            border-radius: 8px;
        }

        .user-message {
            background: #FFD21E;
            color: #111;
            text-align: right;
        }

        .ai-message {
            background: #FF9D00;
            color: #111;
            text-align: left;
        }
    </style>
</head>
<body>
    <div class="chat-container">
        <div id="chat-box"></div>
        <input type="text" id="user-input" placeholder="Type your message...">
        <button id="send-button">Send</button>
    </div>

    <script>
        const chatBox = document.getElementById('chat-box');
        const userInput = document.getElementById('user-input');
        const sendButton = document.getElementById('send-button');

        sendButton.addEventListener('click', () => {
            // Handle sending user input to the server
            const message = userInput.value;
            // Make a POST request to the server to get the AI response
            fetch('/get_response', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                body: new URLSearchParams({ user_input: message })
            })
            .then(response => response.json())
            .then(data => {
                // Display the AI response in the chat box
                // You can customize the format as per your requirements
                chatBox.innerHTML += <div class="chat-message user-message">${message}</div>;
                chatBox.innerHTML += <div class="chat-message ai-message">${data}</div>;
            });
        });
    </script>
</body>
</html>