Skip to content

Commit 540b844

Browse files
authored
Add files via upload
1 parent f6c528c commit 540b844

1 file changed

Lines changed: 230 additions & 60 deletions

File tree

app.js

Lines changed: 230 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ document.addEventListener("contextmenu", function (e) {
3535

3636
// ---- Smooth loading ----
3737

38-
document.addEventListener("DOMContentLoaded", function() {
39-
document.body.classList.add('loaded');
38+
document.addEventListener("DOMContentLoaded", function () {
39+
document.body.classList.add("loaded");
4040
});
4141

42-
// Gsap Animation
42+
// Gsap Animation
4343

44-
window.addEventListener('load', () => {
44+
window.addEventListener("load", () => {
4545
// Animate the navbar
4646
// gsap.from("nav", { duration: 1.5, y: -50, opacity: 0, ease: "power2.out" });
4747

@@ -65,26 +65,31 @@ window.addEventListener('load', () => {
6565
});
6666

6767
// Animate the bottom player controls
68-
gsap.from(".bottom", { duration: 1.5, y: 50, opacity: 0, ease: "power2.out", delay: 1 });
68+
gsap.from(".bottom", {
69+
duration: 1.5,
70+
y: 50,
71+
opacity: 0,
72+
ease: "power2.out",
73+
delay: 1,
74+
});
6975
});
7076

71-
gsap.to('.footer-container', {
77+
gsap.to(".footer-container", {
7278
opacity: 1,
7379
y: 0,
7480
duration: 1.5,
75-
ease: 'power3.out',
76-
delay: 0.3
81+
ease: "power3.out",
82+
delay: 0.3,
7783
});
7884

79-
gsap.to('.footer-bottom', {
85+
gsap.to(".footer-bottom", {
8086
opacity: 1,
8187
y: 0,
8288
duration: 1.2,
83-
ease: 'power3.out',
84-
delay: 0.5
89+
ease: "power3.out",
90+
delay: 0.5,
8591
});
8692

87-
8893
// Scrolling to top
8994

9095
const scrollToTopBtn = document.getElementById("scrollToTop");
@@ -101,89 +106,254 @@ scrollToTopBtn.addEventListener("click", () => {
101106
window.scrollTo({ top: 0, behavior: "smooth" });
102107
});
103108

104-
// Toggle Chatbot Visibility
109+
// Chatbot DeepSeek ----
110+
105111
function toggleChatbot() {
106-
const chatbot = document.querySelector('.chatbot-container');
107-
chatbot.style.display = chatbot.style.display === 'flex' ? 'none' : 'flex';
112+
const chatbot = document.querySelector(".chatbot-container");
113+
chatbot.style.display = chatbot.style.display === "flex" ? "none" : "flex";
108114
}
109115

110-
// Predefined Responses (Detailed)
111116
const responses = [
112-
{
113-
keywords: ["who is affan", "what affan does", "about affan", "affan asghar", "md affan asghar"],
114-
response: "MD Affan Asghar is a passionate Full Stack Web Developer and Computer Science Engineering student, dedicated to building beautiful, responsive, and user-friendly websites. 💻🚀"
115-
},
116-
{ keywords: ["your name", "who are you", "creator", "made you", "built you","build"], response: "I'm a chatbot created by MD Affan Asghar. 😊" },
117-
{ keywords: ["developer name", "who made you", "who is your developer"], response: "My developer is MD Affan Asghar. 🚀" },
118-
{ keywords: ["phone number", "contact", "mobile", "phone"], response: "You can contact MD Affan Asghar at 📞 9339828230." },
119-
{ keywords: ["email", "mail", "gmail"], response: "You can reach him at 📧 affanasgar8@gmail.com." },
120-
{ keywords: ["address", "location", "where do you live"], response: "He lives at 🏠 Kankinara, Kolkata, West Bengal." },
121-
{ keywords: ["skills", "expertise", "technologies", "tech stack"], response: "He is skilled in 🔥 Full-Stack Web Development, Node.js, React, Php, MySQL MongoDB, Express.js, JavaScript, HTML, CSS, and more!" },
122-
{ keywords: ["projects", "work", "portfolio", "project"], response: "His projects include 🎯 WanderLust-Holidays-Rental-Homes, Simtrak Solution, IVMS, and a Weather App using React. 🚀" },
123-
{ keywords: ["portfolio", "website", "profile"], response: "Check out his portfolio here: 🌐 (Provide your portfolio link)." },
124-
{ keywords: ["college", "education", "study", "degree"], response: "He is currently pursuing B.Tech in Computer Science Engineering (CSE) at 🏫 Narula Institute of Technology." },
125-
{ keywords: ["internship", "experience", "job"], response: "He worked as a Web Developer Intern at 💼 Simtrak Solution Pvt Ltd." },
126-
{ keywords: ["final year project", "academic project"], response: "His final year project is a full-stack web development project that aims to revolutionize the industry. 🚀" },
127-
{ keywords: ["hobbies", "interests", "passion"], response: "He loves 💻 coding, designing beautiful websites, learning new tech, and contributing to open-source projects. 🚀" },
128-
{ keywords: ["social media", "linkedin", "github"], response: "You can connect with him here:\n🔗 LinkedIn: https://linkedin.com/in/mdaffanasghar/\n🐱 GitHub: https://github.com/affancoder" },
129-
{ keywords: ["career", "future plans", "goal"], response: "His goal is to become a highly skilled full-stack developer and work on innovative tech projects. 🚀" },
130-
{ keywords: ["freelance", "hire", "services"], response: "Yes! He is available for freelance projects. Contact him at 📧 affanasgar8@gmail.com." },
131-
{ keywords: ["hi", "hello", "hey","hii"], response: "Hello! How can I assist you today? 😊" },
132-
{ keywords: ["bye", "goodbye", "see you"], response: "Goodbye! Have a great day! 😊" },
117+
{
118+
keywords: [
119+
"who is affan",
120+
"what affan does",
121+
"about affan",
122+
"affan asghar",
123+
"md affan asghar",
124+
"tell me about affan",
125+
"who are you",
126+
],
127+
response:
128+
"MD Affan Asghar is a passionate Full Stack Web Developer and Computer Science Engineering student, dedicated to building beautiful, responsive, and user-friendly websites. 💻🚀",
129+
},
130+
{
131+
keywords: ["your name", "creator", "made you", "built you", "build", "who created you"],
132+
response: "I'm a chatbot created by MD Affan Asghar. 😊",
133+
},
134+
{
135+
keywords: ["developer name", "who made you", "who is your developer"],
136+
response: "My developer is MD Affan Asghar. 🚀",
137+
},
138+
{
139+
keywords: ["phone number", "contact", "mobile", "phone", "how to contact", "reach affan"],
140+
response: "You can contact MD Affan Asghar at 📞 9339828230.",
141+
},
142+
{
143+
keywords: ["email", "mail", "gmail", "email address"],
144+
response: "You can reach him at 📧 affanasgar8@gmail.com.",
145+
},
146+
{
147+
keywords: ["address", "location", "where do you live", "where is affan"],
148+
response: "He lives at 🏠 Kankinara, Kolkata, West Bengal.",
149+
},
150+
{
151+
keywords: ["skills", "expertise", "technologies", "tech stack", "what can affan do"],
152+
response:
153+
"He is skilled in 🔥 Full-Stack Web Development, Node.js, React, Php, MySQL MongoDB, Express.js, JavaScript, HTML, CSS, and more!",
154+
},
155+
{
156+
keywords: ["projects", "work", "portfolio", "project", "what has affan built"],
157+
response:
158+
"His projects include 🎯 WanderLust-Holidays-Rental-Homes, Full Stack NoHate website, and a Weather App using React,etc. 🚀",
159+
},
160+
{
161+
keywords: ["portfolio", "website", "profile", "personal website"],
162+
response: "Check out his portfolio here: 🌐 https://portfolio-affan.netlify.app/.",
163+
},
164+
{
165+
keywords: ["college", "education", "study", "degree", "where did affan study"],
166+
response:
167+
"He is currently pursuing B.Tech in Computer Science Engineering (CSE) at 🏫 Narula Institute of Technology.",
168+
},
169+
{
170+
keywords: ["internship", "experience", "job", "work experience"],
171+
response:
172+
"He worked as a Web Developer Intern at 💼 Simtrak Solution Pvt Ltd.",
173+
},
174+
{
175+
keywords: ["final year project", "academic project", "college project"],
176+
response:
177+
"His final year project is a full-stack web development project that aims to revolutionize the industry. 🚀",
178+
},
179+
{
180+
keywords: ["hobbies", "interests", "passion", "what does affan like"],
181+
response:
182+
"He loves 💻 coding, designing beautiful websites, learning new tech, and contributing to open-source projects. 🚀",
183+
},
184+
{
185+
keywords: ["social media", "linkedin", "github", "twitter", "instagram"],
186+
response:
187+
"You can connect with him here:\n🔗 LinkedIn: https://linkedin.com/in/mdaffanasghar/\n🐱 GitHub: https://github.com/affancoder",
188+
},
189+
{
190+
keywords: ["career", "future plans", "goal", "aspirations"],
191+
response:
192+
"His goal is to become a highly skilled full-stack developer and work on innovative tech projects. 🚀",
193+
},
194+
{
195+
keywords: ["freelance", "hire", "services", "available for work"],
196+
response:
197+
"Yes! He is available for freelance projects. Contact him at 📧 affanasgar8@gmail.com.",
198+
},
199+
{
200+
keywords: ["hi", "hello", "hey", "hii", "greetings"],
201+
response: "Hello! How can I assist you today? 😊",
202+
},
203+
{
204+
keywords: ["bye", "goodbye", "see you", "good night"],
205+
response: "Goodbye! Have a great day! 😊",
206+
},
207+
{
208+
keywords: ["thank", "thanks", "appreciate"],
209+
response: "You're welcome! Let me know if you need anything else about Affan. 😊",
210+
},
133211
];
134212

135-
// Function to Find Best Response (Smart Matching)
136213
function findBestResponse(userMessage) {
137214
userMessage = userMessage.toLowerCase();
138-
215+
216+
// First check for exact matches
217+
for (let entry of responses) {
218+
if (entry.keywords.some(keyword =>
219+
userMessage === keyword ||
220+
userMessage.includes(keyword) ||
221+
new RegExp(`\\b${keyword}\\b`).test(userMessage)
222+
)) {
223+
return entry.response;
224+
}
225+
}
226+
227+
// Then check for partial matches
139228
let bestMatch = null;
140229
let highestMatchCount = 0;
141230

142231
for (let entry of responses) {
143-
let matchCount = entry.keywords.filter(keyword => userMessage.includes(keyword)).length;
144-
145-
if (matchCount > highestMatchCount) {
146-
highestMatchCount = matchCount;
147-
bestMatch = entry.response;
148-
}
232+
let matchCount = entry.keywords.filter(keyword =>
233+
userMessage.includes(keyword)
234+
).length;
235+
236+
if (matchCount > highestMatchCount) {
237+
highestMatchCount = matchCount;
238+
bestMatch = entry.response;
239+
}
149240
}
150241

151-
return bestMatch || "I'm still learning! 😊 Ask me anything about MD Affan Asghar.";
242+
return bestMatch || null;
243+
}
244+
245+
// Enhanced API call with better fallbacks
246+
async function callDeepSeekAPI(userMessage) {
247+
// Don't call API for simple greetings or common questions
248+
const simpleQuestions = ["hi", "hello", "hey", "bye", "thank"];
249+
if (simpleQuestions.some(q => userMessage.toLowerCase().includes(q))) {
250+
return null;
251+
}
252+
253+
try {
254+
const response = await fetch("https://api.deepseek.com/v1/chat/completions", {
255+
method: "POST",
256+
headers: {
257+
"Authorization": "Bearer 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",
258+
"Content-Type": "application/json",
259+
},
260+
body: JSON.stringify({
261+
model: "deepseek-chat",
262+
messages: [
263+
{
264+
role: "system",
265+
content: "You are an assistant that answers questions specifically about MD Affan Asghar, a Full Stack Developer. Keep responses brief (1-2 sentences max) and relevant to Affan's skills, projects, education, or contact info. If the question isn't about Affan, politely decline to answer."
266+
},
267+
{
268+
role: "user",
269+
content: userMessage
270+
}
271+
],
272+
temperature: 0.3, // Lower temperature for more focused answers
273+
max_tokens: 100
274+
}),
275+
timeout: 5000 // Add timeout
276+
});
277+
278+
if (!response.ok) {
279+
throw new Error(`API request failed with status ${response.status}`);
280+
}
281+
282+
const data = await response.json();
283+
284+
if (!data.choices?.[0]?.message?.content) {
285+
throw new Error("Invalid API response structure");
286+
}
287+
288+
return data.choices[0].message.content;
289+
} catch (error) {
290+
console.error("DeepSeek API error:", error);
291+
return null; // Return null to trigger local fallback
292+
}
152293
}
153294

154-
// Send Message
155295
function sendMessage() {
156296
const userInput = document.getElementById("userInput");
157297
const message = userInput.value.trim();
158298
if (message === "") return;
159299

160-
// Add User Message
161300
addMessage(message, "user-message");
301+
userInput.value = "";
162302

163-
// Get Bot Response
164-
setTimeout(() => {
303+
// Show typing indicator
304+
const messageContainer = document.getElementById("chatbotMessages");
305+
const typingIndicator = document.createElement("div");
306+
typingIndicator.className = "bot-message typing";
307+
typingIndicator.textContent = "AffanBot is typing...";
308+
typingIndicator.id = "typingIndicator";
309+
messageContainer.appendChild(typingIndicator);
310+
messageContainer.scrollTop = messageContainer.scrollHeight;
311+
312+
setTimeout(async () => {
313+
try {
314+
// Remove typing indicator
315+
const indicator = document.getElementById("typingIndicator");
316+
if (indicator) indicator.remove();
317+
318+
// First try local responses
165319
let botResponse = findBestResponse(message);
166-
addMessage(botResponse, "bot-message");
167-
}, 1000);
168320

169-
userInput.value = "";
321+
// If no local match found, try API
322+
if (!botResponse) {
323+
const apiResponse = await callDeepSeekAPI(message);
324+
botResponse = apiResponse ||
325+
"I'm designed to answer questions about MD Affan Asghar. Could you ask something specific about his skills, projects, or contact information?";
326+
}
327+
328+
addMessage(botResponse, "bot-message");
329+
} catch (error) {
330+
console.error("Error generating response:", error);
331+
addMessage("I'm having some trouble right now. Please try asking something specific about Affan's skills or projects.", "bot-message");
332+
}
333+
}, 1500);
170334
}
171335

172-
// Handle Enter Key
173336
function handleKeyPress(event) {
174337
if (event.key === "Enter") {
175-
sendMessage();
338+
sendMessage();
176339
}
177340
}
178341

179-
// Add Message to Chat
180342
function addMessage(text, className) {
181343
const messageContainer = document.getElementById("chatbotMessages");
182344
const messageDiv = document.createElement("div");
183345
messageDiv.className = className;
184-
messageDiv.textContent = text;
346+
347+
// Handle newlines in responses
348+
if (typeof text === 'string' && text.includes('\n')) {
349+
text.split('\n').forEach((line, i) => {
350+
if (i > 0) messageDiv.appendChild(document.createElement('br'));
351+
messageDiv.appendChild(document.createTextNode(line));
352+
});
353+
} else {
354+
messageDiv.textContent = text;
355+
}
356+
185357
messageContainer.appendChild(messageDiv);
186-
187-
// Scroll to Bottom
188358
messageContainer.scrollTop = messageContainer.scrollHeight;
189-
}
359+
}

0 commit comments

Comments
 (0)