Skip to content

Repository files navigation

Campus Chatbot with NLP

A full-stack intelligent chatbot application designed for university/campus environments, featuring NLP-based question answering, timetable management, and student services.

Overview

This project consists of three main components:

  1. NLP Training Pipeline - Uses sentence transformers for semantic understanding of campus-related queries
  2. Backend API - FastAPI server providing RESTful endpoints for chatbot functionalities
  3. Frontend UI - React-based user interface with Material-UI components

Features

  • NLP-Powered Q&A: Semantic search using sentence embeddings and cosine similarity
  • Timetable Management: Access class schedules and timetables
  • Student Services:
    • Submit complaints
    • Share suggestions
    • View mess menu
    • View cafe menu
  • Data Integration: Handles classes, subjects, teachers, and scheduling information

Project Structure

invie-chatbot/
├── chat/
│   ├── backend/
│   │   └── main.py              # FastAPI backend server
│   └── frontend/
│       ├── public/              # Static assets
│       └── src/
│           ├── App.js           # Main React component
│           └── index.js         # Entry point
├── chatbot_nlp_training.ipynb   # NLP model training notebook
├── timetablecsv.ipynb           # Timetable processing notebook
├── classes.csv                  # Class data
├── subjects.csv                 # Subject data
├── teachers.csv                 # Teacher data
├── processed_qa_data.csv        # Preprocessed Q&A pairs
├── question_embeddings.npy      # Pre-computed question embeddings
└── new queries.json             # Query dataset

Tech Stack

Backend

  • FastAPI - Modern Python web framework
  • CORS Middleware - Cross-origin resource sharing support

Frontend

  • React 19 - UI framework
  • Material-UI (MUI) - Component library
  • Emotion - CSS-in-JS styling

NLP/ML

  • sentence-transformers - Sentence embeddings
  • scikit-learn - Cosine similarity and ML utilities
  • pandas - Data manipulation
  • numpy - Numerical computations

Installation

Prerequisites

  • Python 3.8+
  • Node.js 14+
  • npm or yarn

Backend Setup

# Navigate to backend directory
cd chat/backend

# Install Python dependencies
pip install fastapi uvicorn sentence-transformers scikit-learn pandas numpy

# Run the backend server
uvicorn main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

# Navigate to frontend directory
cd chat/frontend

# Install dependencies
npm install

# Start the development server
npm start

The frontend will be available at http://localhost:3000 and the backend at http://localhost:8000.

NLP Training

The chatbot uses a pre-trained sentence transformer model to understand and respond to queries:

  1. Open the training notebook:

    jupyter notebook chatbot_nlp_training.ipynb
  2. Training Process:

    • Load Q&A data from JSON files
    • Preprocess questions (lowercase, remove special characters)
    • Generate sentence embeddings using SentenceTransformer
    • Compute cosine similarity for query matching
    • Save embeddings to question_embeddings.npy
  3. Model: Uses pre-trained sentence transformer models (e.g., all-MiniLM-L6-v2) for semantic understanding

API Endpoints

Method Endpoint Description
GET / Health check
GET /timetable Fetch timetable data
POST /complaint Submit a complaint
POST /suggestion Submit a suggestion
GET /mess-menu Get mess menu
GET /cafe-menu Get cafe menu

Data Files

  • classes.csv - Class schedules and information
  • subjects.csv - Subject details and metadata
  • teachers.csv - Faculty information
  • processed_qa_data.csv - Cleaned question-answer pairs
  • question_embeddings.npy - Pre-computed embeddings for fast retrieval
  • new queries.json - Sample queries for testing

Frontend Features

  • Modern gradient background design
  • Responsive Material-UI components
  • Real-time backend connectivity check
  • Clean and intuitive user interface

Development

Running Tests (Frontend)

cd chat/frontend
npm test

Building for Production

cd chat/frontend
npm run build

Usage Example

  1. Start the backend server
  2. Launch the frontend application
  3. The chatbot will connect to the backend automatically
  4. Users can:
    • Ask questions about campus facilities
    • Check timetables
    • Submit feedback
    • View dining options

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is open source and available for educational purposes.

Acknowledgments

  • Sentence Transformers library for NLP capabilities
  • FastAPI for the robust backend framework
  • Material-UI for the beautiful UI components

Contact

For questions or support, please open an issue in the repository.


Note: This is a development version. For production deployment, ensure proper security measures, environment variables, and API authentication are implemented.

About

Intelligent campus chatbot leveraging sentence embeddings and cosine similarity, built with FastAPI, React, and Material-UI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages