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