An AI-powered assistant that answers workplace safety questions using OSHA regulations and safety standards through Retrieval-Augmented Generation (RAG).
Safety Advisor Copilot is a sophisticated RAG-based chatbot that provides accurate, context-aware answers to workplace safety questions. By leveraging OSHA's Code of Federal Regulations (CFR) Part 1910 and modern AI technologies, it serves as an intelligent assistant for safety professionals, HR teams, and anyone interested in workplace safety compliance.
Key Features:
git clone https://github.com/abdullah-ax/safety-advisor-copilot.git
cd safety-advisor-copilot
# Install Poetry if you haven't already
curl -sSL https://install.python-poetry.org | python3 -
# Install project dependencies
poetry install
# Using Docker (recommended)
docker run -d \
--name pgvector-db \
-e POSTGRES_USER=langchain \
-e POSTGRES_PASSWORD=langchain \
-e POSTGRES_DB=langchain \
-p 6024:5432 \
pgvector/pgvector:pg16
# Install Ollama from https://ollama.ai
# Pull the embedding model
ollama pull snowflake-arctic-embed:22m
# Run Ollama server (if not already running)
ollama serve
# Copy the example env file
cp .env.example .env
# Edit .env and add your Groq API key
GROQ_API_KEY=your_api_key_here
# Run the notebook to load and embed the OSHA documents
poetry run jupyter notebook examples/test_utils.ipynb
# Execute all cells to create the vector embeddings
poetry run uvicorn src.main:app --reload --port 8000
# In a new terminal
poetry run streamlit run src/streamlit_app.py
Visit http://localhost:8501 to interact with the chatbot! ๐
Question: What are the requirements for fall protection?
Answer: Based on the OSHA regulations, fall protection is required when employees are working at heights of 4 feet or more in general industry settings. Protection methods include guardrails, safety nets, or personal fall arrest systems...
Sources: Shows relevant CFR sections with similarity scores for transparency.
The system uses a two-stage retrieval process:
Documents are split using Hugging Face tokenizers to:
Building this project deepened my understanding of:
safety-advisor-copilot/
โโโ src/
โ โโโ main.py # FastAPI backend with RAG endpoints
โ โโโ streamlit_app.py # Streamlit frontend UI
โ โโโ utils.py # RAG pipeline utilities
โโโ data/
โ โโโ CFR_occupational_safety.pdf # OSHA regulations document
โโโ examples/
โ โโโ test_utils.ipynb # Jupyter notebook for document indexing
โโโ docs/
โ โโโ images/ # Screenshots and diagrams
โโโ .env.example # Environment variable template
โโโ .gitignore # Git ignore rules
โโโ pyproject.toml # Poetry dependencies
โโโ README.md # This file
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ for workplace safety | Report an Issue | Request a Feature
6 commits
1 commits
Python
100.0%
An AI-powered assistant that answers workplace safety questions using OSHA regulations and safety standards through Retrieval-Augmented Generation (RAG).
Safety Advisor Copilot is a sophisticated RAG-based chatbot that provides accurate, context-aware answers to workplace safety questions. By leveraging OSHA's Code of Federal Regulations (CFR) Part 1910 and modern AI technologies, it serves as an intelligent assistant for safety professionals, HR teams, and anyone interested in workplace safety compliance.
Key Features:
git clone https://github.com/abdullah-ax/safety-advisor-copilot.git
cd safety-advisor-copilot
# Install Poetry if you haven't already
curl -sSL https://install.python-poetry.org | python3 -
# Install project dependencies
poetry install
# Using Docker (recommended)
docker run -d \
--name pgvector-db \
-e POSTGRES_USER=langchain \
-e POSTGRES_PASSWORD=langchain \
-e POSTGRES_DB=langchain \
-p 6024:5432 \
pgvector/pgvector:pg16
# Install Ollama from https://ollama.ai
# Pull the embedding model
ollama pull snowflake-arctic-embed:22m
# Run Ollama server (if not already running)
ollama serve
# Copy the example env file
cp .env.example .env
# Edit .env and add your Groq API key
GROQ_API_KEY=your_api_key_here
# Run the notebook to load and embed the OSHA documents
poetry run jupyter notebook examples/test_utils.ipynb
# Execute all cells to create the vector embeddings
poetry run uvicorn src.main:app --reload --port 8000
# In a new terminal
poetry run streamlit run src/streamlit_app.py
Visit http://localhost:8501 to interact with the chatbot! ๐
Question: What are the requirements for fall protection?
Answer: Based on the OSHA regulations, fall protection is required when employees are working at heights of 4 feet or more in general industry settings. Protection methods include guardrails, safety nets, or personal fall arrest systems...
Sources: Shows relevant CFR sections with similarity scores for transparency.
The system uses a two-stage retrieval process:
Documents are split using Hugging Face tokenizers to:
Building this project deepened my understanding of:
safety-advisor-copilot/
โโโ src/
โ โโโ main.py # FastAPI backend with RAG endpoints
โ โโโ streamlit_app.py # Streamlit frontend UI
โ โโโ utils.py # RAG pipeline utilities
โโโ data/
โ โโโ CFR_occupational_safety.pdf # OSHA regulations document
โโโ examples/
โ โโโ test_utils.ipynb # Jupyter notebook for document indexing
โโโ docs/
โ โโโ images/ # Screenshots and diagrams
โโโ .env.example # Environment variable template
โโโ .gitignore # Git ignore rules
โโโ pyproject.toml # Poetry dependencies
โโโ README.md # This file
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ for workplace safety | Report an Issue | Request a Feature
6 commits
1 commits
Python
100.0%