File size: 8,042 Bytes
b35e1e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73e13d9
 
 
 
b35e1e4
73e13d9
 
 
 
 
b35e1e4
 
 
 
 
 
 
609e300
 
8571d7c
b35e1e4
 
 
 
 
 
 
 
 
 
 
 
 
 
73e13d9
b35e1e4
 
 
 
 
 
48ad503
 
 
 
 
 
67c23e4
 
 
 
 
 
 
bbc1e9b
b35e1e4
debad34
596a8a3
 
 
b35e1e4
debad34
b35e1e4
 
debad34
b35e1e4
 
 
596a8a3
b35e1e4
 
 
 
 
 
 
cf9e277
 
 
4a9fa1c
cf9e277
 
 
 
 
 
 
 
 
 
 
 
 
 
b35e1e4
df4aaf4
 
73e13d9
df4aaf4
73e13d9
b35e1e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73e13d9
 
e65f129
73e13d9
 
 
 
 
b35e1e4
 
 
b2b90e7
b35e1e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73e13d9
 
 
 
 
 
 
 
 
 
 
 
 
b35e1e4
73e13d9
 
 
b35e1e4
 
 
596a8a3
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">

    <title>ChatBot</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <style>
      
        .chat-container {
            width: 100%;
            max-width: 1200px; 
            margin: 0 auto; 
            min-width: 100%;
            max-height: 85%;
            overflow-y: auto;
            background-color: #4e4e4e;
        }
    
        .chat-messages {
            
            width: 100%; 
            max-width: calc(100% - 5px); 
            margin: 0 auto;
            display: flex; 
            flex-direction: column; 
            min-width: 90%;
            overflow-y: auto;
        }
    
        .user-message {
           
            color: #ffffff; 
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 10px;
            align-self: flex-start; 
            max-width: 70%; 
            word-wrap: break-word;
            margin-left: 0px;
            font-family: 'Poppins', sans-serif; 
    font-weight: 200; 
    font-size: 16px;
    letter-spacing: 0.5px;
    line-height: 1.6; 
        }
    
        .ai-response {
    color: #ffffff;
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 10px;
    max-width: 80%;
    align-self: flex-start;
    font-family: 'Poppins', sans-serif; 
    font-weight: 200; 
    font-size: 16px; 
    letter-spacing: 0.5px; 
    line-height: 1.5; 
    margin-right: 0px;
}
        #ic {
    max-width: 90%;
    margin: auto;
    min-width: 90%;
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 10px;
    background-color: #1b1b1b;
    border-radius: 10px;
}
#idk,#idk1{
    background-color: #333;
}
#user-input{
    background-color: #1b1b1b;
}
    @media  screen and (max-width:680px) {
        .user-message,.ai-response{
            min-width: 95%;
            max-width: 95%;
        }
        #chat-messages img{
            min-width: 80%;
            width: 80%;
        }
    }
    #chat-messages img{
            width: 40%;
            margin-left: 7px;
            
        }
    </style>
    
    

</head>
<a href="https://discord.gg/A78e55KyuR" target="_blank" style="color: cyan; text-decoration: underline;margin-left: 5px; letter-spacing: 1px;">DISCORD</a>
<a href="https://buymeacoffee.com/mygx" target="_blank" style="color: cyan; text-decoration: underline;margin-left: 5px; letter-spacing: 1px;">Buy Me Coffe </a>
<a href="https://discord.gg/A78e55KyuR" id="userCount" style="color: white;margin-left: 10px;"></a>
<a href="" id="nn" style="color: white;margin-left: 10px;">Please Like This Space ❤</a>

</div>
<body  id="idk1">
    <div class="chat-container flex-1 flex flex-col" id="idk">
        <div class=" rounded-lg shadow-md flex-1">
         
           
            <div id="chat-messages" class="px-4 py-6 chat-messages">
               
            </div>
        </div>
    </div>
    
    <div class="bg-gray-200 px-4 py-3 flex items-center" id="ic">
        <input id="user-input" type="text" autocomplete="off" placeholder="Type your message..." class="flex-1 py-2 px-2 rounded-lg focus:outline-none focus:ring focus:ring-cyan-400 bg-gray-200 text-gray-300">
        <button id='btn' onclick="sendMessage()" class="ml-4 bg-blue-600 text-white px-4 py-2 rounded-lg">Send</button>
    </div>

    
    <script src="https://cdn.socket.io/4.1.3/socket.io.min.js"></script>

    <script>
      alert(` Features :
              * supports Image Generation
              * Real Time Chat With Anyone Around World 
              * Long Context Meomory, Can remember approximately 500+ chats
              * Friendly and Human Like experience
              * Chat Data is not Stored Anywhere 
              * Note your chat messages are not private any connected User can see/reply to it
              #To do :
                * Implement text to Video 
                * Implement various SD models 
                * Implement option to delete Message 
                * NSFW chat filter 
                * Fetaure t create private Rooms`)
        var socket = io.connect('https://apix-30ox.onrender.com');
        var messages = document.getElementById('chat-messages');
        let user = localStorage.getItem("userName")
        console.log(user)
        if(user==null){
            while(true){
            
            user = prompt('Create Your Username')
            if(user!=null  && user!=''  && user!=undefined){
                user.toUpperCase()
              localStorage.setItem("userName",user.toUpperCase() )
                break
            }
        }
        }
        console.log(user)
        var userInput = document.getElementById('user-input');
        socket.on('user_count', function(data) {
    var onlineUsersCount = data.count;
    document.getElementById('userCount').innerText = `Online Users: ${onlineUsersCount}`    
});
        function sendMessage() {
    document.getElementById('btn').disabled = true;
    setTimeout(function(){
        document.getElementById('btn').disabled = false;
    }, 7000); // 5000 milliseconds = 5 seconds

    var message = userInput.value;
    if (message.length > 1200) {
        alert('Message length exceeds 1200 characters!!');
    } else {
        var data = {
            user: user,
            message: message
        };
        socket.emit('message', data);
        userInput.value = '';
    }
}

        userInput.addEventListener("keypress", function(event) {
      if (event.keyCode === 13) { 
        if(!document.getElementById('btn').disabled){
            sendMessage();
        }
        
      }
    });
  
       
        socket.on('message', function(data) {
    var newMessage = document.createElement('p');
    
    var userName = document.createElement('strong');
    userName.textContent = data.user;
    userName.style.color = 'pink'
    userName.style.fontSize = '20px'
    var messageText = document.createTextNode(data.message);
    
    newMessage.appendChild(userName);
    newMessage.appendChild(document.createElement('br'));
    newMessage.appendChild(messageText);
    
    newMessage.classList.add('user-message');
    
    messages.appendChild(newMessage);
});
       
socket.on('response', function(data) {
    if(data.img!=null || data.img!=undefined){
        var img = document.createElement('img');
        img.src = data.img;
        messages.appendChild(img);
    }
    else{

    console.log(data.response); 
    var currentMessage = messages.lastChild;
    if (data.response === 'complete') {
        currentMessage = null;
      document.getElementById('btn').disabled = false
    } else {
        if (!currentMessage || !currentMessage.classList.contains('ai-response')) {
            currentMessage = document.createElement('p');
            currentMessage.classList.add('ai-response');
            
            var aiLabel = document.createElement('h1');
            aiLabel.style.color = 'skyblue'
            aiLabel.textContent = 'AI RESPONSE: ';
            
            currentMessage.appendChild(aiLabel);
            currentMessage.appendChild(document.createElement('br')); 
            
            messages.appendChild(currentMessage);
        }
   
        var responseText = document.createTextNode(data.response);
        
        
        currentMessage.appendChild(responseText);
        
        }

    }   
});




socket.on('image', function(data) {
    if (data.image) {
        var img = document.createElement('img');
        img.src = 'data:image/jpeg;base64,' + data.image;
        document.body.appendChild(img); // Or append to a specific container
    }
});



    </script>
</body>

</html>