File size: 10,750 Bytes
fbb201d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92381ff
 
 
fbb201d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92381ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbb201d
 
 
92381ff
fbb201d
 
92381ff
fbb201d
 
 
 
92381ff
 
fbb201d
 
 
92381ff
 
 
 
 
 
fbb201d
92381ff
 
 
 
 
fbb201d
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Chatbot</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .chat-container {
            height: calc(100vh - 120px);
        }
        .message-animation {
            animation: fadeIn 0.3s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .typing-indicator span {
            animation: bounce 1.5s infinite ease-in-out;
            display: inline-block;
        }
        .typing-indicator span:nth-child(2) {
            animation-delay: 0.2s;
        }
        .typing-indicator span:nth-child(3) {
            animation-delay: 0.4s;
        }
        @keyframes bounce {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-5px); }
        }
    </style>
</head>
<body class="bg-gray-100 font-sans">
    <div class="max-w-4xl mx-auto p-4">
        <!-- Header -->
        <header class="bg-white rounded-t-lg shadow-sm p-4 flex items-center justify-between">
            <div class="flex items-center space-x-3">
                <div class="w-10 h-10 rounded-full bg-gradient-to-r from-blue-500 to-purple-600 flex items-center justify-center text-white">
                    <i class="fas fa-robot text-xl"></i>
                </div>
                <div>
                    <h1 class="font-bold text-lg">AI Assistant</h1>
                    <p class="text-xs text-gray-500">Always here to help</p>
                </div>
            </div>
            <div class="flex space-x-2">
                <button class="p-2 rounded-full hover:bg-gray-100 text-gray-500">
                    <i class="fas fa-ellipsis-v"></i>
                </button>
            </div>
        </header>

        <!-- Chat container -->
        <div class="chat-container bg-white overflow-y-auto p-4 space-y-4" id="chatContainer">
            <!-- Welcome message -->
            <div class="message-animation flex space-x-3">
                <div class="flex-shrink-0">
                    <div class="w-8 h-8 rounded-full bg-gradient-to-r from-blue-500 to-purple-600 flex items-center justify-center text-white">
                        <i class="fas fa-robot text-sm"></i>
                    </div>
                </div>
                <div class="bg-gray-100 rounded-lg p-3 max-w-xs md:max-w-md lg:max-w-lg">
                    <p class="text-gray-800">Hello! I'm your AI assistant. How can I help you today?</p>
                    <p class="text-xs text-gray-500 mt-1">Just now</p>
                </div>
            </div>

            <!-- Sample conversation (will be populated dynamically) -->
            <div id="messagesContainer"></div>

            <!-- Typing indicator (hidden by default) -->
            <div id="typingIndicator" class="hidden flex space-x-3">
                <div class="flex-shrink-0">
                    <div class="w-8 h-8 rounded-full bg-gradient-to-r from-blue-500 to-purple-600 flex items-center justify-center text-white">
                        <i class="fas fa-robot text-sm"></i>
                    </div>
                </div>
                <div class="bg-gray-100 rounded-lg p-3 w-20">
                    <div class="typing-indicator flex space-x-1">
                        <span class="w-2 h-2 bg-gray-400 rounded-full"></span>
                        <span class="w-2 h-2 bg-gray-400 rounded-full"></span>
                        <span class="w-2 h-2 bg-gray-400 rounded-full"></span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Input area -->
        <div class="bg-white rounded-b-lg shadow-sm p-4">
            <form id="chatForm" class="flex space-x-2">
                <div class="flex-grow relative">
                    <input 
                        type="text" 
                        id="userInput" 
                        placeholder="Type your message..." 
                        class="w-full border border-gray-300 rounded-full py-2 px-4 pr-10 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
                        autocomplete="off"
                    >
                    <button type="button" class="absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-blue-500">
                        <i class="far fa-smile"></i>
                    </button>
                </div>
                <button type="submit" class="bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-full w-10 h-10 flex items-center justify-center hover:from-blue-600 hover:to-purple-700 transition">
                    <i class="fas fa-paper-plane"></i>
                </button>
            </form>
            <div class="flex justify-between mt-2 text-xs text-gray-500">
                <p>AI may produce inaccurate information</p>
                <p><i class="fas fa-shield-alt"></i> Secure</p>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const chatForm = document.getElementById('chatForm');
            const userInput = document.getElementById('userInput');
            const messagesContainer = document.getElementById('messagesContainer');
            const chatContainer = document.getElementById('chatContainer');
            const typingIndicator = document.getElementById('typingIndicator');

            // Conversation history for context
            let conversationHistory = [
                { role: "system", content: "You are a helpful AI assistant. Provide clear, concise, and friendly responses." }
            ];

            // Add message to chat
            function addMessage(text, isUser) {
                const messageDiv = document.createElement('div');
                messageDiv.className = `message-animation flex space-x-3 ${isUser ? 'justify-end' : ''}`;
                
                const timestamp = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
                
                messageDiv.innerHTML = `
                    ${!isUser ? `
                    <div class="flex-shrink-0">
                        <div class="w-8 h-8 rounded-full bg-gradient-to-r from-blue-500 to-purple-600 flex items-center justify-center text-white">
                            <i class="fas fa-robot text-sm"></i>
                        </div>
                    </div>
                    ` : ''}
                    <div class="${isUser ? 'bg-blue-500 text-white' : 'bg-gray-100 text-gray-800'} rounded-lg p-3 max-w-xs md:max-w-md lg:max-w-lg">
                        <p>${text}</p>
                        <p class="text-xs ${isUser ? 'text-blue-100' : 'text-gray-500'} mt-1">${timestamp}</p>
                    </div>
                    ${isUser ? `
                    <div class="flex-shrink-0">
                        <div class="w-8 h-8 rounded-full bg-gray-200 flex items-center justify-center text-gray-600">
                            <i class="fas fa-user text-sm"></i>
                        </div>
                    </div>
                    ` : ''}
                `;
                
                messagesContainer.appendChild(messageDiv);
                chatContainer.scrollTop = chatContainer.scrollHeight;
            }

            // Get AI response from Pollinations API
            async function getAIResponse(userMessage) {
                conversationHistory.push({ role: "user", content: userMessage });

                try {
                    const response = await fetch('https://text.pollinations.ai/', {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        body: JSON.stringify({
                            messages: conversationHistory,
                            model: 'openai'
                        })
                    });

                    if (!response.ok) throw new Error('API request failed');

                    const aiMessage = (await response.text()).trim() || "I'm sorry, I couldn't generate a response.";
                    conversationHistory.push({ role: "assistant", content: aiMessage });
                    return aiMessage;
                } catch (error) {
                    console.error('Error:', error);
                    return "I'm having trouble connecting right now. Please try again.";
                }
            }

            // Handle form submission
            chatForm.addEventListener('submit', async function(e) {
                e.preventDefault();
                const message = userInput.value.trim();

                if (message) {
                    // Add user message
                    addMessage(message, true);
                    userInput.value = '';
                    userInput.disabled = true;

                    // Show typing indicator
                    typingIndicator.classList.remove('hidden');
                    chatContainer.scrollTop = chatContainer.scrollHeight;

                    try {
                        const aiResponse = await getAIResponse(message);
                        typingIndicator.classList.add('hidden');
                        addMessage(aiResponse, false);
                    } catch (error) {
                        typingIndicator.classList.add('hidden');
                        addMessage("I'm having trouble responding right now. Please try again.", false);
                    } finally {
                        userInput.disabled = false;
                        userInput.focus();
                    }
                }
            });

            // Auto-focus input
            userInput.focus();
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://deepsite.hf.co/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://deepsite.hf.co" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://deepsite.hf.co?remix=oxyle/aibbotnext" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>