Are you tired of using the same chatbots that feel lifeless and generic? Imagine building your own intelligent assistant—customized, branded, and fully controllable. Whether you’re a tech enthusiast, a developer, or just someone curious, this guide walks you through creating a custom chatbot and automating daily tasks like sending WhatsApp messages to your loved ones.
Welcome to KNCMAP Technologies’ guide to the future—a simple, effective way to kickstart your journey with Python, Streamlit, and OpenRouter AI.
Step-by-Step: Create Your Own Chatbot
Step 1: Prepare Your Development Environment
-
Use PyCharm or any Python IDE.
-
Create a new file, e.g.,
Streamlit.py
.
Step 2: Paste the Code
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 |
import streamlit as st import requests import os import shelve from dotenv import load_dotenv load_dotenv() st.title("KNCMAP-TECHNOLOGIES") USER_AVATAR = "" BOT_AVATAR = "" API_KEY = os.getenv("KNCMAP_API_KEY") MODEL_NAME = "mistralai/mistral-7b-instruct" def load_chat_history(): with shelve.open("chat_history") as db: return db.get("messages", []) def save_chat_history(messages): with shelve.open("chat_history") as db: db["messages"] = messages if "messages" not in st.session_state: st.session_state.messages = load_chat_history() with st.sidebar: if st.button("Delete Chat History"): st.session_state.messages = [] save_chat_history([]) for message in st.session_state.messages: avatar = USER_AVATAR if message["role"] == "user" else BOT_AVATAR with st.chat_message(message["role"], avatar=avatar): st.markdown(message["content"]) if prompt := st.chat_input("How can I help?"): st.session_state.messages.append({"role": "user", "content": prompt}) with st.chat_message("user", avatar=USER_AVATAR): st.markdown(prompt) headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } body = { "model": MODEL_NAME, "messages": st.session_state.messages } try: response = requests.post( "https://openrouter.ai/api/v1/chat/completions", headers=headers, json=body ) result = response.json() answer = result['choices'][0]['message']['content'] with st.chat_message("assistant", avatar=BOT_AVATAR): st.markdown(answer) st.session_state.messages.append({"role": "assistant", "content": answer}) save_chat_history(st.session_state.messages) except Exception as e: with st.chat_message("assistant", avatar=BOT_AVATAR): st.markdown(f"❌ Error: {str(e)}") |
Step 3: Set Up Your .env
File
Create a .env
file in the same directory and add your API key from OpenRouter.ai:
1 2 3 |
KNCMAP_API_KEY=sk-your-key |
Step 4: Install Dependencies
In your terminal:
1 2 3 |
pip install streamlit python-dotenv |
Step 5: Run Your Bot
1 2 3 |
streamlit run Streamlit.py |
Your chatbot is now live in your browser!
Modify the Chatbot for Real-Life Use Cases
1. Stock Trading for Grandpa
Want to make your grandfather happy by automating stock insights?
-
Integrate financial APIs like Yahoo Finance or Alpha Vantage.
-
Modify the prompt to retrieve stock advice or daily summaries.
-
Use scheduled tasks to fetch morning reports using
schedule
orAPScheduler
.
2. Compete in Gucci’s Fashion Design Challenge
Help your father outshine the competition:
-
Train your model on fashion datasets.
-
Use the chatbot to brainstorm fashion themes and generate new ideas.
-
Integrate image generation with tools like DALL·E or Replicate to create design concepts.
3. Automate Sweet Messages to Your Partner
Nothing says love like a well-timed message. Automate WhatsApp love notes using Python:
Tools You’ll Need:
-
pywhatkit
for sending WhatsApp messages -
schedule
orAPScheduler
for time-based automation
Sample Script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import pywhatkit import schedule import time def send_morning_message(): pywhatkit.sendwhatmsg("+254712345678", "Good morning, love! ", 5, 0) def send_day_checkin(): pywhatkit.sendwhatmsg("+254712345678", "Hope your day is going well! ", 12, 0) def send_evening_message(): pywhatkit.sendwhatmsg("+254712345678", "Good night, my heart ❤️", 20, 0) schedule.every().day.at("05:00").do(send_morning_message) schedule.every().day.at("12:00").do(send_day_checkin) schedule.every().day.at("20:00").do(send_evening_message) while True: schedule.run_pending() time.sleep(60) |
Conclusion
With just a few lines of code, you’ve built a chatbot, customized it, and even used it for heartfelt communication or competitive advantage. At KNCMAP Technologies, we believe in blending simplicity with impact—and now it’s your turn.
Create. Customize. Automate. ❤️