mobenta commited on
Commit
6ad59a3
·
verified ·
1 Parent(s): 2c72ae7

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +107 -0
index.html CHANGED
@@ -46,6 +46,113 @@
46
  }
47
 
48
  body {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
50
  color: var(--text);
51
  line-height: 1.6;
 
46
  }
47
 
48
  body {
49
+ <!-- Chat Bot Interface -->
50
+ <div class="fixed bottom-4 right-4 z-50">
51
+ <div id="chat-container" class="hidden w-80 bg-bg-card rounded-lg shadow-xl border border-border dark:border-gray-700">
52
+ <div class="p-4 border-b border-border dark:border-gray-700">
53
+ <h3 class="font-semibold text-text">Mindset Coach</h3>
54
+ </div>
55
+ <div id="chat-messages" class="h-64 overflow-y-auto p-4 space-y-4 text-sm"></div>
56
+ <div class="p-4 border-t border-border dark:border-gray-700">
57
+ <div class="flex gap-2">
58
+ <input id="user-input" type="text" placeholder="Ask about emotional control..."
59
+ class="flex-1 p-2 border border-border rounded-lg bg-bg text-text
60
+ focus:outline-none focus:ring-2 focus:ring-primary">
61
+ <button id="send-btn" class="btn btn-primary px-4 py-2">
62
+ <i class="fas fa-paper-plane"></i>
63
+ </button>
64
+ </div>
65
+ <p class="text-xs mt-2 text-text-light">Powered by Gemini AI</p>
66
+ </div>
67
+ </div>
68
+ <button id="chat-toggle"
69
+ class="w-12 h-12 bg-primary text-white rounded-full shadow-lg
70
+ hover:bg-primary-dark transition-transform transform hover:scale-110">
71
+ <i class="fas fa-comment-dots text-lg"></i>
72
+ </button>
73
+ </div>
74
+
75
+ <!-- Add this to your existing script -->
76
+ <script>
77
+ // Chat functionality
78
+ document.getElementById('chat-toggle').addEventListener('click', () => {
79
+ document.getElementById('chat-container').classList.toggle('hidden');
80
+ });
81
+
82
+ document.getElementById('send-btn').addEventListener('click', async () => {
83
+ const userInput = document.getElementById('user-input');
84
+ const message = userInput.value.trim();
85
+ if (!message) return;
86
+
87
+ // Add user message
88
+ addMessage(message, 'user');
89
+ userInput.value = '';
90
+
91
+ try {
92
+ // Add loading state
93
+ const loadingId = addMessage('Analyzing...', 'bot', true);
94
+
95
+ // Get page content context
96
+ const pageContent = document.body.innerText.substring(0, 2000);
97
+
98
+ // Call your Hugging Face API endpoint
99
+ const response = await fetch('/api/chat', {
100
+ method: 'POST',
101
+ headers: { 'Content-Type': 'application/json' },
102
+ body: JSON.stringify({
103
+ message: message,
104
+ context: `Help users with mindset techniques from this content: ${pageContent}`
105
+ })
106
+ });
107
+
108
+ const data = await response.json();
109
+ const botResponse = data.candidates[0].content.parts[0].text;
110
+
111
+ // Update loading message
112
+ updateMessage(loadingId, botResponse, 'bot');
113
+
114
+ } catch (error) {
115
+ console.error('Error:', error);
116
+ updateMessage(loadingId, 'Sorry, I need to practice more mindfulness. Try again later.', 'bot');
117
+ }
118
+ });
119
+
120
+ // Helper functions
121
+ let messageCount = 0;
122
+
123
+ function addMessage(text, sender, isLoading = false) {
124
+ const id = `msg-${messageCount++}`;
125
+ const messagesDiv = document.getElementById('chat-messages');
126
+ messagesDiv.innerHTML += `
127
+ <div id="${id}" class="flex ${sender === 'user' ? 'justify-end' : 'justify-start'}">
128
+ <div class="max-w-[85%] p-3 rounded-lg ${
129
+ sender === 'user'
130
+ ? 'bg-primary text-white'
131
+ : 'bg-bg-alt text-text border border-border'
132
+ }">
133
+ ${text}${isLoading ? ' <i class="fas fa-spinner fa-spin"></i>' : ''}
134
+ </div>
135
+ </div>
136
+ `;
137
+ messagesDiv.scrollTop = messagesDiv.scrollHeight;
138
+ return id;
139
+ }
140
+
141
+ function updateMessage(id, newText, sender) {
142
+ const messageDiv = document.getElementById(id);
143
+ if (messageDiv) {
144
+ messageDiv.innerHTML = `
145
+ <div class="max-w-[85%] p-3 rounded-lg ${
146
+ sender === 'user'
147
+ ? 'bg-primary text-white'
148
+ : 'bg-bg-alt text-text border border-border'
149
+ }">
150
+ ${newText}
151
+ </div>
152
+ `;
153
+ }
154
+ }
155
+ </script>
156
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
157
  color: var(--text);
158
  line-height: 1.6;