Spaces:
Sleeping
Sleeping
Update app.py
Browse files191 unmodified lines1921931941951961971981 unmodified line20020120220320420520620720820921021162 unmodified lines2742752762772782792802 unmodified lines2832842852862872882892902912922932942 unmodified lines29729829930030130230330430530630730830930 unmodified lines3403413423433443454 unmodified lines350351352353354355356357358359360361362363364365366367368369191 unmodified linescontext = "\n\n---\n\n".join(relevant_chunks)system_prompt = f"""You are Kevs AI Assistant, a strict, grounded chatbot for Michael Onoriode's professional portfolio and services.**CRITICAL RULES:**1. ONLY use the provided context below to answer. DO NOT use any external knowledge or prior training.2. If the user asks something not covered in the context, say: "I don't have that information in my knowledge base. Please ask about Michael's skills, projects (like inventory intelligence, MuzoScents, Kevs Digital), automation systems, experience, or the digital marketing services he offers (web design, SEO, analytics, email marketing, audits)."1 unmodified line4. Keep answers concise (max 3 sentences unless context requires more).5. If the user asks for pricing or service details, provide the information from the context if available, otherwise direct them to request a detailed pricelist via WhatsApp.6. If the user asks for contact, offer the WhatsApp button (provide the WhatsApp number from configuration).**Context (from portfolio and services pages):**{context}User question: {user_message}Answer strictly from context:"""if GROQ_API_KEY:62 unmodified lines}# ------------------------------------------------------------------# Widget JS (left side + WhatsApp handoff)# ------------------------------------------------------------------@app.get("/chat-widget.js", response_class=PlainTextResponse)async def widget_js():2 unmodified linesconst API_URL = '{PRODUCTION_HOST}';const WHATSAPP_NUMBER = '{WHATSAPP_NUMBER}';const widgetDiv = document.createElement('div');widgetDiv.innerHTML = `<div id="kevs-chat-btn" style="position:fixed; bottom:20px; left:20px; width:60px; height:60px; background:#2563eb; border-radius:50%; cursor:pointer; z-index:10000; display:flex; align-items:center; justify-content:center; box-shadow:0 4px 12px rgba(0,0,0,0.2);"><svg width="28" height="28" viewBox="0 0 24 24" fill="white"><path d="M20 2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4V4c0-1.1-.9-2-2-2z"/></svg></div><div id="kevs-chat-window" style="position:fixed; bottom:90px; left:20px; width:360px; height:520px; background:white; border-radius:16px; display:none; flex-direction:column; z-index:10000; box-shadow:0 8px 24px rgba(0,0,0,0.2); overflow:hidden;"><div style="background:#2563eb; color:white; padding:12px 16px; display:flex; justify-content:space-between; align-items:center;"><span style="font-weight:bold;">๐ค Ask Kevs AI</span><div>2 unmodified lines</div></div><div id="kevs-messages" style="flex:1; overflow-y:auto; padding:12px; background:#f9fafb;"></div><div style="padding:12px; border-top:1px solid #e5e7eb; display:flex; gap:8px;"><input id="kevs-input" placeholder="Ask about my skills, projects, services, or experience..." style="flex:1; padding:8px; border:1px solid #d1d5db; border-radius:24px; outline:none;" /><button id="kevs-send" style="background:#2563eb; color:white; border:none; padding:8px 16px; border-radius:24px; cursor:pointer;">Send</button></div></div>`;document.body.appendChild(widgetDiv);const btn = document.getElementById('kevs-chat-btn');const chatWin = document.getElementById('kevs-chat-window');30 unmodified linesif (!msg) return;addMessage(msg, true);input.value = '';try {{const res = await fetch(API_URL + '/api/chat', {{method: 'POST',4 unmodified linesaddMessage(data.response, false);}} catch (err) {{addMessage('โ ๏ธ Network error. Please try again or use WhatsApp.', false);}}}}btn.onclick = () => chatWin.style.display = 'flex';closeBtn.onclick = () => chatWin.style.display = 'none';sendBtn.onclick = sendMessage;input.onkeypress = (e) => e.key === 'Enter' && sendMessage();waBtn.onclick = () => {{const waUrl = `https://wa.me/{WHATSAPP_NUMBER.replace('+','')}?text=Hello%20Michael%2C%20I%20have%20a%20question%20about%20your%20portfolio.`;window.open(waUrl, '_blank');}};addMessage("๐ Hi! I'm Kevs AI. I can answer questions about Michael's skills, automation systems, projects, experience, and the digital marketing services he offers. If I can't help, click WhatsApp to talk directly.", false);}})();"""191 unmodified lines1921931941951961971 unmodified line19920020120220320420520620762 unmodified lines2702712722732742752762 unmodified lines2792802812822832842852862872882892902912922932942952962 unmodified lines29930030130230330430530630730830931030 unmodified lines3413423433443453463473484 unmodified lines353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388191 unmodified linescontext = "\n\n---\n\n".join(relevant_chunks)system_prompt = f"""You are Kevs AI Assistant, a strict, grounded chatbot for Michael Onoriode's professional portfolio and services.**CRITICAL RULES:**1. ONLY use the provided context below to answer. DO NOT use any external knowledge or prior training.2. If the user asks something not covered in the context, say: "I don't have that information in my knowledge base. Please ask about Michael's skills, projects (like inventory intelligence, MuzoScents, Kevs Digital), automation systems, experience, or the digital marketing services he offers (web design, SEO, analytics, email marketing, audits)."1 unmodified line4. Keep answers concise (max 3 sentences unless context requires more).5. If the user asks for pricing or service details, provide the information from the context if available, otherwise direct them to request a detailed pricelist via WhatsApp.6. If the user asks for contact, offer the WhatsApp button (provide the WhatsApp number from configuration).**Context (from portfolio and services pages):**{context}User question: {user_message}Answer strictly from context:"""if GROQ_API_KEY:62 unmodified lines}# ------------------------------------------------------------------# FIXED Widget JS (left side, resolves laptop typing issue)# ------------------------------------------------------------------@app.get("/chat-widget.js", response_class=PlainTextResponse)async def widget_js():2 unmodified linesconst API_URL = '{PRODUCTION_HOST}';const WHATSAPP_NUMBER = '{WHATSAPP_NUMBER}';// Avoid duplicate widgetif (document.getElementById('kevs-chat-root')) return;const widgetRoot = document.createElement('div');widgetRoot.id = 'kevs-chat-root';document.body.appendChild(widgetRoot);widgetRoot.innerHTML = `<div id="kevs-chat-btn" style="position:fixed; bottom:20px; left:20px; width:60px; height:60px; background:#2563eb; border-radius:50%; cursor:pointer; z-index:99999; display:flex; align-items:center; justify-content:center; box-shadow:0 4px 12px rgba(0,0,0,0.2);"><svg width="28" height="28" viewBox="0 0 24 24" fill="white"><path d="M20 2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4V4c0-1.1-.9-2-2-2z"/></svg></div><div id="kevs-chat-window" style="position:fixed; bottom:90px; left:20px; width:360px; height:520px; background:white; border-radius:16px; display:none; flex-direction:column; z-index:99999; box-shadow:0 8px 24px rgba(0,0,0,0.2); overflow:hidden; font-family: 'Segoe UI', system-ui, sans-serif;"><div style="background:#2563eb; color:white; padding:12px 16px; display:flex; justify-content:space-between; align-items:center;"><span style="font-weight:bold;">๐ค Ask Kevs AI</span><div>2 unmodified lines</div></div><div id="kevs-messages" style="flex:1; overflow-y:auto; padding:12px; background:#f9fafb;"></div><div style="padding:12px; border-top:1px solid #e5e7eb; display:flex; gap:8px; background:white;"><input id="kevs-input" placeholder="Ask about skills, projects, services, or experience..." style="flex:1; padding:8px 12px; border:1px solid #d1d5db; border-radius:24px; outline:none; font-size:14px;" autocomplete="off" /><button id="kevs-send" style="background:#2563eb; color:white; border:none; padding:8px 16px; border-radius:24px; cursor:pointer; font-size:14px;">Send</button></div></div>`;const btn = document.getElementById('kevs-chat-btn');const chatWin = document.getElementById('kevs-chat-window');30 unmodified linesif (!msg) return;addMessage(msg, true);input.value = '';input.disabled = true;sendBtn.disabled = true;try {{const res = await fetch(API_URL + '/api/chat', {{method: 'POST',4 unmodified linesaddMessage(data.response, false);}} catch (err) {{addMessage('โ ๏ธ Network error. Please try again or use WhatsApp.', false);}} finally {{input.disabled = false;sendBtn.disabled = false;input.focus();}}}}btn.onclick = () => {{chatWin.style.display = 'flex';setTimeout(() => input.focus(), 100);}};closeBtn.onclick = () => chatWin.style.display = 'none';sendBtn.onclick = sendMessage;input.onkeypress = (e) => {{if (e.key === 'Enter') {{e.preventDefault();sendMessage();}}}};// Force input to be interactiveinput.removeAttribute('readonly');input.disabled = false;waBtn.onclick = () => {{const waUrl = `https://wa.me/{WHATSAPP_NUMBER.replace('+','')}?text=Hello%20Michael%2C%20I%20have%20a%20question%20about%20your%20portfolio.`;window.open(waUrl, '_blank');}};addMessage("๐ Hi! I'm Kevs AI. Ask me about Michael's skills, automation systems, projects, or digital marketing services. If I can't help, click WhatsApp to talk directly.", false);}})();"""
app.py+35-16