File size: 3,619 Bytes
e161cb9
 
 
 
 
 
6416f7d
e161cb9
 
 
 
0d8581e
 
e161cb9
 
 
 
 
 
 
 
 
 
0d8581e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
title: Text-to-SQL Converter
emoji: πŸ—„οΈ
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.35.0
app_file: app.py
pinned: false
---

# 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.

## πŸ“ž Support

If you encounter any issues or have questions, please open an issue on the repository.