From 35f16915fc76710cbf5f1b9186c8c5816d052772 Mon Sep 17 00:00:00 2001 From: Nazim Hafeez Date: Wed, 19 Nov 2025 12:47:16 +0000 Subject: [PATCH 1/2] Added chat bot files using start up guide --- .gitignore | 6 +++ .vscode/settings.json | 4 ++ getting-started/amna.py | 7 +++ getting-started/quickstart.py | 16 +++++++ getting-started/test-gemini.py | 23 ++++++++++ getting-started/test-setup.py | 22 +++++++++ requirements.txt | 4 +- .../starter-template/app.py | 45 +++++++++++++++++++ .../starter-template/chatbot.py | 36 ++++++++++++++- .../starter-template/scraper.py | 37 +++++++++++++++ .../starter-template/test_bot.py | 18 ++++++++ .../starter-template/wcc_faqs.json | 20 +++++++++ 12 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 getting-started/amna.py create mode 100644 getting-started/quickstart.py create mode 100644 getting-started/test-gemini.py create mode 100644 getting-started/test-setup.py create mode 100644 sessions/session-01-ai-chatbots/starter-template/app.py create mode 100644 sessions/session-01-ai-chatbots/starter-template/scraper.py create mode 100644 sessions/session-01-ai-chatbots/starter-template/test_bot.py create mode 100644 sessions/session-01-ai-chatbots/starter-template/wcc_faqs.json diff --git a/.gitignore b/.gitignore index b7faf40..81fa5a7 100644 --- a/.gitignore +++ b/.gitignore @@ -205,3 +205,9 @@ cython_debug/ marimo/_static/ marimo/_lsp/ __marimo__/ + +# .gitignore +.env +.env.local +*.key + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c0e8e39 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.analysis.autoImportCompletions": true, + "python.analysis.typeCheckingMode": "standard" +} \ No newline at end of file diff --git a/getting-started/amna.py b/getting-started/amna.py new file mode 100644 index 0000000..4bf6fb3 --- /dev/null +++ b/getting-started/amna.py @@ -0,0 +1,7 @@ +from dotenv import load_dotenv +import os + +load_dotenv() + +project_id = os.getenv("gen-lang-client-0919970423") +location = os.getenv("GCP_LOCATION") diff --git a/getting-started/quickstart.py b/getting-started/quickstart.py new file mode 100644 index 0000000..5d6edb3 --- /dev/null +++ b/getting-started/quickstart.py @@ -0,0 +1,16 @@ +from google.cloud import aiplatform + +# Initialize Vertex AI +aiplatform.init(project="gen-lang-client-0919970423", location="us-central1") + +# Import the generative model +from vertexai.generative_models import GenerativeModel + +# Initialize the model +model = GenerativeModel("gemini-2.5-flash-lite") + +# Make a simple request +response = model.generate_content("What is AI?") + +print("Response:") +print(response.text) \ No newline at end of file diff --git a/getting-started/test-gemini.py b/getting-started/test-gemini.py new file mode 100644 index 0000000..f874d51 --- /dev/null +++ b/getting-started/test-gemini.py @@ -0,0 +1,23 @@ +import os +from dotenv import load_dotenv +import google.generativeai as genai + +# Load environment variables +load_dotenv() + +# Configure API +api_key = os.getenv('GEMINI_API_KEY') +if not api_key: + print("❌ Error: GEMINI_API_KEY not found in .env file") + exit(1) + +genai.configure(api_key=api_key) + +# Test the API +try: + model = genai.GenerativeModel('gemini-2.5-flash-lite') + response = model.generate_content("What is AI? Explain to a novice.") + print("✅ API is working!") + print(f"Response: {response.text}") +except Exception as e: + print(f"❌ Error: {e}") \ No newline at end of file diff --git a/getting-started/test-setup.py b/getting-started/test-setup.py new file mode 100644 index 0000000..f635d23 --- /dev/null +++ b/getting-started/test-setup.py @@ -0,0 +1,22 @@ +import sys +print(f"Python version: {sys.version}") + +try: + from google.cloud import aiplatform + print("✅ google-cloud-aiplatform installed") +except ImportError: + print("❌ google-cloud-aiplatform not found") + +try: + import streamlit + print("✅ streamlit installed") +except ImportError: + print("❌ streamlit not found") + +try: + import dotenv + print("✅ python-dotenv installed") +except ImportError: + print("❌ python-dotenv not found") + +print("\n✅ All packages installed successfully!") \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 09b0fe3..b19a412 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,9 +5,11 @@ # Session 1 (AI Fundamentals & LLM APIs) - REQUIRED # ============================================================================ -google-generativeai>=0.3.0 +google-cloud-aiplatform>=1.26.0 +vertexai>=0.1.0 python-dotenv>=1.0.0 streamlit>=1.28.0 +requests>=2.31.0 # ============================================================================ # Optional: Alternative Platforms (Uncomment to use) diff --git a/sessions/session-01-ai-chatbots/starter-template/app.py b/sessions/session-01-ai-chatbots/starter-template/app.py new file mode 100644 index 0000000..4d4666c --- /dev/null +++ b/sessions/session-01-ai-chatbots/starter-template/app.py @@ -0,0 +1,45 @@ +import streamlit as st +import json +from chatbot import SimpleBot + +st.set_page_config(page_title="WCC Info Bot", page_icon="🤖") + +st.title("🤖 WCC Info Bot") +st.markdown("Ask me anything about Women Coding Community!") + +# Load FAQs +with open("wcc_faqs.json") as f: + wcc_data = json.load(f) + +faq_text = "\n".join([ + f"Q: {faq['question']}\nA: {faq['answer']}" + for faq in wcc_data["faqs"] +]) + +system_prompt = f"""You are a friendly WCC assistant... +{faq_text}""" + +# Initialize bot +if "bot" not in st.session_state: + st.session_state.bot = SimpleBot(system_prompt=system_prompt) + +if "messages" not in st.session_state: + st.session_state.messages = [] + +# Display chat history +for message in st.session_state.messages: + with st.chat_message(message["role"]): + st.markdown(message["content"]) + +# Chat input +if user_input := st.chat_input("Ask me about WCC..."): + st.session_state.messages.append({"role": "user", "content": user_input}) + + with st.chat_message("user"): + st.markdown(user_input) + + response = st.session_state.bot.chat(user_input) + st.session_state.messages.append({"role": "assistant", "content": response}) + + with st.chat_message("assistant"): + st.markdown(response) \ No newline at end of file diff --git a/sessions/session-01-ai-chatbots/starter-template/chatbot.py b/sessions/session-01-ai-chatbots/starter-template/chatbot.py index 09cc5fa..f2e845b 100644 --- a/sessions/session-01-ai-chatbots/starter-template/chatbot.py +++ b/sessions/session-01-ai-chatbots/starter-template/chatbot.py @@ -11,7 +11,7 @@ load_dotenv() # Configure Gemini API -API_KEY = os.getenv("GEMINI_API_KEY") +API_KEY ="AIzaSyBbKBVBiiMuQzfI8CSiIqC02bNXJ_1-nI0" if not API_KEY: raise ValueError( "GEMINI_API_KEY not found in environment variables. " @@ -115,3 +115,37 @@ def main(): if __name__ == "__main__": main() +import json + +# Load WCC FAQs +with open("wcc_faqs.json") as f: + wcc_data = json.load(f) + +# Create FAQ context +faq_text = "\n".join([ + f"Q: {faq['question']}\nA: {faq['answer']}" + for faq in wcc_data["faqs"] +]) + +# Create system prompt with WCC knowledge +system_prompt = f"""You are Maya, the enthusiastic WCC assistant! +You love helping women in tech and are passionate about community. +Always be encouraging and supportive. +Use emojis occasionally to add warmth and supportiveness. +Also be kind and inclusive in your responses. + +Here are the FAQs you should reference: +{faq_text} + +Be warm, encouraging, and inclusive. If you don't know something, suggest they contact the WCC team. +""" + +import logging + +logging.basicConfig(filename='chatbot.log', level=logging.INFO) + +def log_conversation(user_msg, bot_response): + logging.info(f"User: {user_msg}") + logging.info(f"Bot: {bot_response}") + +bot = SimpleBot(system_prompt=system_prompt) \ No newline at end of file diff --git a/sessions/session-01-ai-chatbots/starter-template/scraper.py b/sessions/session-01-ai-chatbots/starter-template/scraper.py new file mode 100644 index 0000000..2c8f31c --- /dev/null +++ b/sessions/session-01-ai-chatbots/starter-template/scraper.py @@ -0,0 +1,37 @@ +import requests +from bs4 import BeautifulSoup +import json + +def scrape_wcc_events(): + """Scrape upcoming events from WCC website""" + # Replace with actual WCC website URL + url = "https://womencoding.community/events" + + try: + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + + events = [] + for event in soup.find_all('div', class_='event'): + events.append({ + "title": event.find('h3').text, + "date": event.find('span', class_='date').text, + "description": event.find('p').text + }) + + return events + except Exception as e: + print(f"Error scraping: {e}") + return [] + +# Use in chatbot +events = scrape_wcc_events() +events_text = "\n".join([ + f"- {e['title']} on {e['date']}: {e['description']}" + for e in events +]) + +system_prompt = f"""You are a WCC assistant. +Upcoming events: +{events_text} +""" \ No newline at end of file diff --git a/sessions/session-01-ai-chatbots/starter-template/test_bot.py b/sessions/session-01-ai-chatbots/starter-template/test_bot.py new file mode 100644 index 0000000..46bea86 --- /dev/null +++ b/sessions/session-01-ai-chatbots/starter-template/test_bot.py @@ -0,0 +1,18 @@ +from chatbot import SimpleBot + +def test_wcc_bot(): + bot = SimpleBot(system_prompt="You are a WCC assistant.") + + # Test basic response + response = bot.chat("What is WCC?") + assert len(response) > 0 + + # Test conversation memory + bot.chat("I'm interested in AI") + response = bot.chat("Can you recommend a session?") + assert "AI" in response or "session" in response.lower() + + print("✅ All tests passed!") + +if __name__ == "__main__": + test_wcc_bot() \ No newline at end of file diff --git a/sessions/session-01-ai-chatbots/starter-template/wcc_faqs.json b/sessions/session-01-ai-chatbots/starter-template/wcc_faqs.json new file mode 100644 index 0000000..0bf8996 --- /dev/null +++ b/sessions/session-01-ai-chatbots/starter-template/wcc_faqs.json @@ -0,0 +1,20 @@ +{ + "faqs": [ + { + "question": "What is WCC?", + "answer": "Women Coding Community is a global community of women in tech..." + }, + { + "question": "How do I join WCC?", + "answer": "Visit our website and sign up for free..." + }, + { + "question": "When are the sessions?", + "answer": "Sessions are held every other Wednesday at 7 PM EST..." + }, + { + "question": "Can I volunteer?", + "answer": "Absolutely! We're always looking for volunteers..." + } + ] +} \ No newline at end of file From d4c90c898f6b8ab0eb16e5737f6fb891b5e56d70 Mon Sep 17 00:00:00 2001 From: amna-nazim-gigani Date: Wed, 19 Nov 2025 13:16:58 +0000 Subject: [PATCH 2/2] Added Dev Container Folder --- .devcontainer/devcontainer.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..486aa50 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +{ + "name": "Python 3", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm", + "customizations": { + "codespaces": { + "openFiles": [ + "README.md", + "sessions/session-01-ai-chatbots/starter-template/chatbot.py" + ] + }, + "vscode": { + "settings": {}, + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance" + ] + } + }, + "updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y