Shahiniuz/Data_Explorer
CDC Diabetes Health Data Explorer
An AI-powered tool for querying real CDC health survey data using OpenAI's function calling API. Built for my capstone project.
About the Data
I'm using real CDC data from the 2014 Behavioral Risk Factor Surveillance System (BRFSS). It's a huge dataset - 253,680 actual patient survey responses with 21 different health indicators. You can verify this is real public health data from the UCI repository: https://archive.ics.uci.edu/dataset/891
The dataset includes things like:
- Diabetes status (binary - yes/no)
- BMI, blood pressure, cholesterol levels
- Lifestyle factors (smoking, physical activity, diet)
- Demographics (age, sex, education, income)
- Other health conditions
How it Works
The key idea here is privacy - the AI never sees the actual patient data. Here's the flow:
- User asks a question like "what's the diabetes rate among smokers?"
- AI gets the database schema (just table/column names)
- AI uses function calling to decide which tools to use
- Tools execute locally on your machine
- Results go straight to the user
The AI is basically just writing SQL queries based on the schema, then the queries run locally. Patient data never leaves your computer.
Function Calling Implementation
This project uses OpenAI's function calling API with 3 tools:
Tool 1: execute_sql_query
- Executes SELECT queries on the database
- Has safety checks to block DELETE, DROP, etc.
- Returns results as JSON
Tool 2: get_database_statistics
- Gets overview stats (total patients, diabetes rates, etc.)
- Useful for general questions about the dataset
Tool 3: create_support_ticket
- Creates a support ticket when users need help
- Logs the ticket to console with timestamp
- AI can suggest this if it can't answer something
The AI decides which tools to call based on the user's question. Sometimes it calls multiple tools in sequence.
Setup
Requirements
- Python 3.9+
- OpenAI API key
- Streamlit
Installation
# Install dependencies
pip install -r requirements.txt
# Download the CDC data (this might take a minute)
python3 download_real_data.py
# Create .env file with your API key
echo "OPENAI_API_KEY=your_key_here" > .env
# Run it
streamlit run app.pyThen open http://localhost:8501
Database Schema
The main table is patient_health_data with 253,680 rows. Some key fields:
Binary indicators (0 or 1):
- Diabetes_binary - has diabetes/prediabetes
- HighBP - high blood pressure
- HighChol - high cholesterol
- Smoker - currently smokes
- PhysActivity - physically active
- Plus more...
Numeric fields:
- BMI - body mass index
- GenHlth - general health rating (1-5)
- Age - age group (1-13)
- MentHlth - days of poor mental health (0-30)
- PhysHlth - days of poor physical health (0-30)
There are also 2 views (pre-computed aggregations):
- diabetesbyage - diabetes stats by age group
- healthrisksummary - health metrics by general health rating
Safety Features
Important for a healthcare data project:
- Only SELECT queries allowed
- Dangerous operations (DELETE, DROP, ALTER, etc.) are blocked
- All queries logged to console
- Query validation before execution
- Patient data never sent to OpenAI
Example Questions
Try asking things like:
- "Show me diabetes rates by age group"
- "What's the relationship between BMI and diabetes?"
- "How many patients have high blood pressure?"
- "Compare health stats between smokers and non-smokers"
- "Get overall database statistics"
Screenshots
Will add screenshots here showing:
- Main interface
- Function calling in action
- Query results
- Support ticket creation
Console Logging
Everything is logged to the console so you can see what's happening:
==================================================
Starting CDC Diabetes Data Explorer
==================================================
2025-11-13 12:00:00 - INFO - User asked: What's the diabetes rate?
2025-11-13 12:00:00 - INFO - Schema retrieved
2025-11-13 12:00:00 - INFO - Calling OpenAI API...
2025-11-13 12:00:01 - INFO - Calling function: get_database_statistics
2025-11-13 12:00:01 - INFO - Stats retrieved - 253,680 total patients
2025-11-13 12:00:02 - INFO - Getting final response...
2025-11-13 12:00:03 - INFO - Done processing queryProject Structure
Capstone1/
├── app.py # Main application
├── download_real_data.py # Script to download CDC data
├── diabetes_health.db # SQLite database (10MB)
├── requirements.txt # Python dependencies
├── .env # API key (you create this)
└── README.md # This fileTech Stack
- Python 3.9
- Streamlit for the UI
- OpenAI GPT-4o-mini with function calling
- SQLite database
- Real CDC data from UCI ML Repository
Data Source
This uses real public health data from the CDC's Behavioral Risk Factor Surveillance System. The dataset is available through the UCI Machine Learning Repository and is in the public domain.
Citation:
- CDC BRFSS 2014
- 253,680 survey responses
- 21 health indicators
- https://archive.ics.uci.edu/dataset/891
Notes
- The AI only sees database structure, not actual data
- All queries run locally
- Function calling is properly implemented (not just text generation)
- Real healthcare data (not generated)
- Built for educational/capstone project purposes
Feel free to explore the code - it's all commented and should be pretty straightforward.
