How kuldip-1662/document-sentiment-analyzer-chatbot works
Project type and purpose
• This is a full-stack, AI-powered PDF Emotion Analyzer & Chatbot web application.
• The frontend is built in Streamlit; the backend is in FastAPI (api.py/app.py) and Python scripts handle PDF processing, sentiment prediction, and chat logic via LangChain.
File structure
Top-level files & directories:
• PromptTemplate.py, api.py, app.py, chat.py, config.py, model_prediction.py, pdf_processing.py – core backend logic and configurations
• README.md, requirements.txt – documentation & dependencies
• sentiment/ – helper modules for sentiment model loading & text extraction
• sentiment_model_training/ – standalone training pipeline
README for additional insights
• Two main features: Sentiment Analysis (using ModernBERT+PyTorch) and Chat (using LangChain + Groq for data generation).
• Tech stack: ModernBERT, PyTorch, LangChain, FastAPI, Streamlit.
Main components & interactions
a. Components
1. Streamlit Frontend
2. FastAPI Backend
• PDF Processing Module (pdf_processing.py)
• Sentiment Prediction Module (model_prediction.py + sentiment/model_loading.py + sentiment/text_extraction.py)
• Chat Module (chat.py leveraging LangChain, embeddings, PromptTemplate)
3. Sentiment Training Pipeline (sentiment_model_training/)
4. External Services
• Groq (dataset generation)
• LLM provider (for LangChain chat)
5. Configuration (config.py)
b. Relationships & Data Flows
• User uploads PDF via Streamlit → HTTP POST to FastAPI
• Backend → pdf_processing extracts text → either
– Sentiment path → model_prediction invokes ModernBERT PyTorch model → return emotion scores
– Chat path → LangChain document loader & retriever + LLM chain → return conversational answer
• Results returned to Frontend for display
• Training pipeline is offline; uses sentiment_data.csv → dataset.py, text_cleaning, preprocessing, model.py, train.py to produce a fine-tuned model stored for loading.
c. Architectural patterns & design principles
• Separation of concerns: frontend vs. API vs. model logic vs. training pipeline
• Modular design: each feature in its own module
• Dependency injection via config.py for keys, model paths, LLM endpoints
d. Key technologies
• Streamlit (UI)
• FastAPI (HTTP API)
• ModernBERT + PyTorch (sentiment)
• LangChain (chat orchestration)
• Groq (data augmentation)
Elements
• Labels for each component (e.g., “PDF Processor”, “LangChain Chat Engine”)
– Blue for frontend
– Green for backend services
– Orange for ML model/training
– Gray for external services