This project simplifies data analysis by removing the need to write SQL manually. Users can enter questions in plain English, and the application automatically:
- Converts natural language to SQL using Gemini API
- Executes queries on Snowflake database
- Displays results in tabular and chart format
- Allows users to download results as CSV
This makes data analysis accessible to non-technical users.
- Python
- Streamlit (Web interface)
- Snowflake (Cloud database)
- Gemini API (AI SQL generation)
- Plotly (Data visualization)
- Pandas (Data handling)
- Snowflake Python Connector
- Natural language to SQL conversion
- Snowflake database integration
- Query execution and result display
- Automatic chart generation
- CSV download option
- Query history tracking
myproject/
│
├── app/
│ ├── main.py # Streamlit web app
│ ├── ai_sql_generator.py # Converts question to SQL using Gemini
│ ├── query_executor.py # Executes SQL in Snowflake
│ ├── snowflake_client.py # Snowflake connection
│ ├── visualization.py # Creates charts
│ ├── history_manager.py # Saves query history
│ ├── config.py # Loads environment variables
│
├── data/
│ └── sample_data.py
│
├── .env # API keys and credentials
├── requirements.txt
├── run.py
└── README.md
User Input (Natural Language)
│
▼
Gemini API generates SQL
│
▼
Snowflake executes SQL
│
▼
Results returned to app
│
▼
Display table + visualization + CSV download
Table: SALES
Columns:
- order_id
- customer_name
- product
- category
- region
- quantity
- price
- order_date
git clone <your-repo-url>
cd myproject
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
Create .env file:
GEMINI_API_KEY=your_api_key
SNOWFLAKE_USER=your_user
SNOWFLAKE_PASSWORD=your_password
SNOWFLAKE_ACCOUNT=your_account
SNOWFLAKE_WAREHOUSE=your_warehouse
SNOWFLAKE_ROLE=your_role
streamlit run app/main.py
User Input:
Show total sales by region
Generated SQL:
SELECT region, SUM(price * quantity) AS total_sales
FROM sales
GROUP BY region;
Uses Gemini API to convert natural language to SQL.
Executes SQL query on Snowflake and returns results.
Creates connection to Snowflake database.
Generates charts using Plotly.
Handles user interface using Streamlit.
Problem: Non-technical users cannot write SQL queries.
Solution: AI automatically generates SQL from natural language.
Problem: Manual data analysis is slow.
Solution: Automated query execution and visualization.
- Support multiple databases
- Add authentication system
- Improve SQL accuracy with schema awareness
- Add dashboard saving feature