How sagnik24-k/chatbot2 works
Project Type and Purpose
• Type: Full-stack, client-server web application.
• Purpose: A study-assistant chatbot built on Python/Flask and the Google Gemini AI model, with light front-end in HTML/CSS and integrations to Wikipedia.
File Structure
Top-level files & directories:
• Frontend: index.html (Flask template), CSS (Tailwind) embedded.
• Backend: Chat.py (Flask app entry point, called “app.py” in README), Main.py (auxiliary runner?), Chat_utils.py, wek.py.
• Data/config: responses.json (knowledge base), .env (Gemini API key), Api.txt (maybe API usage examples).
• __pycache__, .idea: ignore for architecture.
README for Insights
• Routes:
– “/” renders chat interface
– “/process_input” handles user submissions
• Modules:
– Chat_utils.py: input preprocessing, fallback logic, local knowledge_base via responses.json
– wek.py: fetches & sanitizes Wikipedia book summaries
– External: Google Gemini API via google.generativeai
• Data flow: browser → Flask → choose Gemini vs. local vs. Wikipedia → store session → render page
Main Components & Interactions
a. Components
– Client (Browser): Renders index.html, sends user input via POST
– Web Server (Flask in Chat.py): Receives requests, manages sessions
• Chat_utils module
• wek module
• Session store (in-memory or Flask sessions)
– Data Store: responses.json (intents & canned replies)
– External Services:
• Google Gemini AI API (requires .env key)
• Wikipedia API (via wek.py)
b. Relationships
1. User types question → Browser POST to /process_input
2. Flask route dispatches to Chat_utils or wek
3. Chat_utils either:
• Loads fallback from responses.json
• Or calls Google Gemini API
4. If “Book review” intent detected → wek.py calls Wikipedia API
5. Response is assembled, stored in session, and returned as rendered HTML
c. Architectural Patterns
– Client-Server (thin client, server-side rendering)
– Modular backend: separation of concerns (routing vs. AI logic vs. external-API logic)
– Config management: .env for secrets
d. Technologies
– Python 3.x, Flask
– HTML5, Tailwind CSS (embedded in index.html)
– google.generativeai library
– wikipedia Python library
– JSON for knowledge base
Diagramming Conventions
• Blue rectangles for frontend components
• Green for backend modules
• Orange clouds for external services
– Group related modules inside a bigger “Flask Server” container.
Detailed Component Breakdown
• Browser
– index.html (Tailwind layout, chat UI, sidebar)
• Flask Server
– Chat.py (routing, session mgmt)
– Chat_utils.py (intent classification, fallback logic)
– wek.py (Wikipedia integration)
– responses.json (knowledge base)
– .env (Gemini API key)
• External Services
– Google Gemini AI API
– Wikipedia API
Putting It All Together: