A newer version of the Streamlit SDK is available:
1.42.0
metadata
title: Text To Sql Example Explanation
emoji: π
colorFrom: pink
colorTo: red
sdk: streamlit
sdk_version: 1.32.2
app_file: app.py
pinned: false
license: mit
SQL Query Generator
Effortlessly transform your natural language inputs into SQL queries using this Streamlit application powered by Google Generative AI.
Features
- Generate SQL queries from natural language input.
- Optionally specify schema and table names for precise query generation.
- Get sample expected responses for the generated SQL query.
- Receive a simple explanation of the SQL query.
Prerequisites
1. Install Required Tools
Ensure the following tools are installed:
- Python 3.8+
2. Obtain API Key
- Get an API key for Google Generative AI from Google Cloud Console.
- Save the API key for later configuration.
Installation
Clone the Repository
# Clone this repository
git clone <repository_url>
cd <repository_folder>
Create and Activate a Virtual Environment
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# For Windows:
venv\Scripts\activate
# For MacOS/Linux:
source venv/bin/activate
Install Dependencies
# Install required Python libraries
pip install -r requirements.txt
Configuration
- Create a
.env
file in the root of your project directory. - Add your Google API key to the
.env
file as follows:
GOOGLE_API_KEY="<your_google_api_key>"
Usage
Run the Application
streamlit run app.py
Input Details
- Enter your natural language query in the text box.
- Optionally, specify a schema name.
- Enter a table name (this is mandatory).
- Click on Generate SQL Query.
Outputs
The application will provide:
- The generated SQL query.
- A sample tabular response for the query.
- A simple explanation of the SQL query.
Project Structure
.
βββ app.py # Main Streamlit app
βββ .env # Environment file for API key
βββ requirements.txt # Python dependencies
βββ README.md # This file
Troubleshooting
1. Error: Please enter the table name!
- Ensure the Table Name field is not empty.
2. API Key Issues
- Verify the API key in your
.env
file is correct and has sufficient permissions.
3. Missing Dependencies
- Ensure all dependencies are installed via
pip install -r requirements.txt
.
Contributing
Feel free to fork this repository, raise issues, or submit pull requests. Contributions are always welcome!
License
This project is licensed under the MIT License.
Acknowledgments
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference