File size: 13,379 Bytes
155cb4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Advanced AI Assistant</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Inter', sans-serif;
        }
        body {
            background: linear-gradient(135deg, #1a1a2e, #16213e);
            color: #fff;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            line-height: 1.6;
        }
        .container {
            width: 95%;
            max-width: 1200px;
            display: flex;
            gap: 20px;
            height: 90vh;
        }
        .chat-container {
            flex: 2;
            background: rgba(255, 255, 255, 0.05);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        .suggestions {
            flex: 1;
            background: rgba(255, 255, 255, 0.03);
            border-radius: 20px;
            padding: 20px;
            overflow-y: auto;
            display: none;
        }
        @media (min-width: 1024px) {
            .suggestions {
                display: block;
            }
        }
        .suggestion-item {
            padding: 10px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 10px;
            margin-bottom: 10px;
            cursor: pointer;
            transition: all 0.3s;
        }
        .suggestion-item:hover {
            background: rgba(255, 255, 255, 0.1);
            transform: translateY(-2px);
        }
        .chat-header {
            background: rgba(255, 255, 255, 0.05);
            padding: 20px;
            text-align: center;
            font-weight: 600;
            font-size: 1.2em;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        .chat-box {
            height: calc(90vh - 140px);
            overflow-y: auto;
            padding: 20px;
        }
        .message {
            margin: 10px 0;
            padding: 12px 16px;
            border-radius: 15px;
            max-width: 80%;
            animation: fadeIn 0.3s ease-in;
            position: relative;
            font-size: 0.95em;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .user-message {
            background: #4a4af4;
            margin-left: auto;
            border-bottom-right-radius: 5px;
        }
        .ai-message {
            background: rgba(255, 255, 255, 0.05);
            margin-right: auto;
            border-bottom-left-radius: 5px;
        }
        .typing-indicator {
            display: none;
            padding: 12px 16px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 15px;
            margin: 10px 0;
            width: fit-content;
        }
        .dot {
            display: inline-block;
            width: 6px;
            height: 6px;
            background: #fff;
            border-radius: 50%;
            margin-right: 3px;
            animation: bounce 1s infinite;
        }
        .dot:nth-child(2) { animation-delay: 0.2s; }
        .dot:nth-child(3) { animation-delay: 0.4s; }
        @keyframes bounce {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-5px); }
        }
        .input-area {
            padding: 20px;
            background: rgba(255, 255, 255, 0.05);
            display: flex;
            gap: 10px;
            align-items: center;
        }
        input {
            flex: 1;
            padding: 12px 16px;
            border: none;
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.1);
            color: #fff;
            font-size: 0.95em;
            transition: all 0.3s;
        }
        input:focus {
            outline: none;
            background: rgba(255, 255, 255, 0.15);
            box-shadow: 0 0 0 2px rgba(74, 74, 244, 0.3);
        }
        button {
            padding: 12px 24px;
            border: none;
            border-radius: 10px;
            background: #4a4af4;
            color: #fff;
            cursor: pointer;
            transition: all 0.3s;
            font-weight: 500;
        }
        button:hover {
            background: #3a3ad4;
            transform: translateY(-2px);
        }
        ::-webkit-scrollbar {
            width: 6px;
        }
        ::-webkit-scrollbar-track {
            background: transparent;
        }
        ::-webkit-scrollbar-thumb {
            background: rgba(255, 255, 255, 0.2);
            border-radius: 3px;
        }
        .category {
            color: rgba(255, 255, 255, 0.6);
            font-size: 0.9em;
            margin-bottom: 15px;
            font-weight: 500;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="chat-container">
            <div class="chat-header">Advanced AI Assistant</div>
            <div class="chat-box" id="chatBox">
                <div class="message ai-message">Hello! I'm your advanced AI assistant. I can help you with a wide range of tasks including calculations, conversions, coding help, general knowledge questions, and more!</div>
                <div class="typing-indicator" id="typingIndicator">
                    <span class="dot"></span>
                    <span class="dot"></span>
                    <span class="dot"></span>
                </div>
            </div>
            <div class="input-area">
                <input type="text" id="userInput" placeholder="Type your message...">
                <button onclick="sendMessage()">Send</button>
            </div>
        </div>
        <div class="suggestions">
            <div class="category">Suggested Topics</div>
            <div class="suggestion-item" onclick="useSuggestion('Tell me about quantum computing')">Quantum Computing</div>
            <div class="suggestion-item" onclick="useSuggestion('How do I start learning programming?')">Programming Basics</div>
            <div class="suggestion-item" onclick="useSuggestion('Explain machine learning in simple terms')">Machine Learning</div>
            <div class="suggestion-item" onclick="useSuggestion('What are some productivity tips?')">Productivity Tips</div>
            <div class="suggestion-item" onclick="useSuggestion('Help me with JavaScript promises')">JavaScript Help</div>
        </div>
    </div>

    <script>
        // Large predefined knowledge base (sample - extend with more)
        const knowledgeBase = {
            // General Knowledge
            "quantum computing": "Quantum computing is a type of computing that uses quantum-mechanical phenomena like superposition and entanglement to perform calculations. Unlike classical computers that use bits (0 or 1), quantum computers use quantum bits or qubits that can exist in multiple states simultaneously.",
            
            "machine learning": "Machine learning is a subset of artificial intelligence that enables systems to learn and improve from experience without being explicitly programmed. It uses algorithms and statistical models to analyze patterns in data.",
            
            "programming basics": "Programming is the process of creating a set of instructions that tell a computer how to perform a task. Key concepts include variables, control structures (if/else, loops), functions, and data structures. Popular beginner languages include Python and JavaScript.",
            
            // Technical Help
            "javascript promises": "Promises in JavaScript are objects representing the eventual completion (or failure) of an asynchronous operation. They help manage asynchronous code more elegantly. Example:\n\nnew Promise((resolve, reject) => {\n    // async code here\n    if(success) resolve(result);\n    else reject(error);\n});",
            
            "css flexbox": "Flexbox is a CSS layout model that allows you to design flexible responsive layouts. Key properties include:\n- display: flex\n- flex-direction\n- justify-content\n- align-items",
            
            // Math Operations
            "calculate": (input) => {
                const expression = input.replace("calculate", "").trim();
                try {
                    return `The result is: ${eval(expression)}`;
                } catch {
                    return "Sorry, I couldn't perform that calculation. Please check the format.";
                }
            },
            // Unit Conversions
            "convert": (input) => {
                const conversions = {
                    "celsius_to_fahrenheit": (c) => (c * 9/5 + 32).toFixed(2),
                    "fahrenheit_to_celsius": (f) => ((f - 32) * 5/9).toFixed(2),
                    "km_to_miles": (km) => (km * 0.621371).toFixed(2),
                    "miles_to_km": (mi) => (mi * 1.60934).toFixed(2)
                };
                const parts = input.toLowerCase().split(" ");
                
                if(parts.includes("celsius") && parts.includes("fahrenheit")) {
                    const temp = parseFloat(parts[1]);
                    return `${temp}°C is equal to ${conversions.celsius_to_fahrenheit(temp)}°F`;
                }
                // Add more conversion types here
                
                return "I can convert between various units. Try: 'convert 20 celsius to fahrenheit'";
            },
            // Productivity Tips
            "productivity tips": "Here are some key productivity tips:\n1. Use the Pomodoro Technique\n2. Break large tasks into smaller ones\n3. Set clear goals and deadlines\n4. Minimize distractions\n5. Take regular breaks\n6. Use task management tools\n7. Practice time-blocking",
            
            // Add thousands more entries here for different topics
        };
        // General responses for common queries
        const generalResponses = {
            "hello": ["Hi there! How can I help you today?", "Hello! What would you like to learn about?", "Greetings! I'm here to assist you."],
            "thank you": ["You're welcome!", "Happy to help!", "Anytime! Let me know if you need anything else."],
            "bye": ["Goodbye! Have a great day!", "See you later! Feel free to return if you have more questions.", "Bye! Thanks for chatting!"],
        };
        const chatBox = document.getElementById("chatBox");
        const userInput = document.getElementById("userInput");
        const typingIndicator = document.getElementById("typingIndicator");
        userInput.addEventListener("keypress", (e) => {
            if (e.key === "Enter") {
                sendMessage();
            }
        });
        function useSuggestion(text) {
            userInput.value = text;
            sendMessage();
        }
        function sendMessage() {
            const message = userInput.value.trim();
            if (!message) return;
            addMessage(message, "user-message");
            userInput.value = "";
            typingIndicator.style.display = "block";
            chatBox.scrollTop = chatBox.scrollHeight;
            setTimeout(() => {
                typingIndicator.style.display = "none";
                
                let response = generateResponse(message.toLowerCase());
                addMessage(response, "ai-message");
            }, 1000 + Math.random() * 1000); // Random delay for more natural feel
        }
        function generateResponse(input) {
            // Check general responses first
            for (let key in generalResponses) {
                if (input.includes(key)) {
                    return generalResponses[key][Math.floor(Math.random() * generalResponses[key].length)];
                }
            }
            // Check knowledge base
            for (let key in knowledgeBase) {
                if (input.includes(key)) {
                    return typeof knowledgeBase[key] === 'function' 
                        ? knowledgeBase[key](input)
                        : knowledgeBase[key];
                }
            }
            // Handle calculations
            if (input.startsWith("calculate")) {
                return knowledgeBase.calculate(input);
            }
            // Handle conversions
            if (input.startsWith("convert")) {
                return knowledgeBase.convert(input);
            }
            return "I'm not sure about that. Could you try rephrasing your question? Or ask me about topics like programming, quantum computing, or machine learning.";
        }
        function addMessage(text, className) {
            const messageDiv = document.createElement("div");
            messageDiv.className = `message ${className}`;
            messageDiv.textContent = text;
            chatBox.insertBefore(messageDiv, typingIndicator);
            chatBox.scrollTop = chatBox.scrollHeight;
        }
    </script>
</body>
</html>