Spaces:
Runtime error
Runtime error
title: Text-to-SQL Converter | |
emoji: ποΈ | |
colorFrom: blue | |
colorTo: purple | |
sdk: gradio | |
sdk_version: 5.35.0 | |
app_file: app.py | |
pinned: false | |
license: mit | |
# Text-to-SQL Converter | |
A powerful AI model that converts natural language questions into SQL queries. | |
## Features | |
- Natural language to SQL conversion | |
- Beautiful web interface | |
- REST API endpoints | |
- Batch processing support | |
## Usage | |
Simply enter your question and table headers to get SQL queries instantly! | |
## π Features | |
- **Natural Language to SQL**: Convert plain English questions to SQL queries | |
- **Web Interface**: Beautiful ChatGPT-like interface for easy interaction | |
- **Batch Processing**: Handle multiple queries at once | |
- **Real-time Generation**: Fast and accurate SQL generation | |
- **Health Monitoring**: Built-in health checks and monitoring | |
## π― Usage | |
### Web Interface | |
Simply visit the web interface and: | |
1. Enter your question in natural language | |
2. Provide the table headers (comma-separated) | |
3. Click "Generate SQL Query" to get your SQL | |
### API Usage | |
#### Single Query | |
```python | |
import requests | |
response = requests.post("https://your-space-url.hf.space/predict", json={ | |
"question": "How many employees are older than 30?", | |
"table_headers": ["id", "name", "age", "department", "salary"] | |
}) | |
sql_query = response.json()["sql_query"] | |
print(sql_query) | |
``` | |
#### Batch Queries | |
```python | |
response = requests.post("https://your-space-url.hf.space/batch", json={ | |
"queries": [ | |
{ | |
"question": "How many employees are older than 30?", | |
"table_headers": ["id", "name", "age", "department", "salary"] | |
}, | |
{ | |
"question": "Show all employees in IT department", | |
"table_headers": ["id", "name", "age", "department", "salary"] | |
} | |
] | |
}) | |
results = response.json()["results"] | |
``` | |
## π Example Queries | |
| Question | Table Headers | Generated SQL | | |
|----------|---------------|---------------| | |
| "How many employees are older than 30?" | id, name, age, department, salary | `SELECT COUNT(*) FROM table WHERE age > 30` | | |
| "Show all employees in IT department" | id, name, age, department, salary | `SELECT * FROM table WHERE department = 'IT'` | | |
| "What is the average salary by department?" | id, name, age, department, salary | `SELECT department, AVG(salary) FROM table GROUP BY department` | | |
## π§ API Endpoints | |
- `GET /` - Web interface | |
- `GET /api` - API information | |
- `POST /predict` - Generate SQL for single question | |
- `POST /batch` - Generate SQL for multiple questions | |
- `GET /health` - Health check | |
- `GET /docs` - Interactive API documentation | |
## ποΈ Model Architecture | |
This model is based on **Salesforce CodeT5** and fine-tuned specifically for text-to-SQL conversion using PEFT (Parameter Efficient Fine-Tuning). The model has been trained on a diverse dataset of natural language questions and their corresponding SQL queries. | |
### Model Details | |
- **Base Model**: Salesforce/codet5-base | |
- **Fine-tuning**: PEFT (LoRA) | |
- **Input Format**: Structured text with table headers and questions | |
- **Output**: SQL queries | |
## π Deployment | |
This application is deployed on Hugging Face Spaces and can be accessed via the provided URL. The deployment includes: | |
- FastAPI backend | |
- Modern web interface | |
- Model serving with automatic scaling | |
- Health monitoring | |
## π License | |
This project is open source and available under the MIT License. | |
## π€ Contributing | |
Contributions are welcome! Please feel free to submit a Pull Request. | |