QueryCraft is a self-contained Colab notebook that generates SQL queries based on a provided database schema and an English text description. It leverages the Llama3.2 language model to interpret the user's query, converting it into a corresponding SQL statement.
The project includes an intuitive Gradio interface for input of schema details and text query intructions. Generate SQL without manually writing queries.
- Natural Language Input: Convert plain English questions into SQL queries.
- Schema Interpretation: Understands provided DB schemas to generate precise SQL statements.
- Open the Colab Notebook Demo.
- Low memory will run fine, but enabling the following runtime-type settings will allow for faster processing:
- High-RAM
- Hardware Accelerator GPU
- Low memory will run fine, but enabling the following runtime-type settings will allow for faster processing:
- Select 'Runtime->Run All'
- Use the Gradio interface to input:
- A database schema.
- A query in English text.
- The tool will return the corresponding SQL statement based on the input.
Input Txt
"How many teachers teach only one class?"
Input Schema:
CREATE TABLE Students (
student_id INT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255) UNIQUE
);
CREATE TABLE Teachers (
teacher_id INT PRIMARY KEY,
name VARCHAR(255),
specialty VARCHAR(255)
);
CREATE TABLE Classes (
class_id INT PRIMARY KEY,
title VARCHAR(255),
teacher_id INT,
FOREIGN KEY (teacher_id) REFERENCES Teachers(teacher_id)
);
CREATE TABLE ClassroomAssignments (
assignment_id INT PRIMARY KEY,
class_id INT,
classroom VARCHAR(255),
class_time TIME,
FOREIGN KEY (class_id) REFERENCES Classes(class_id)
);
CREATE TABLE StudentClassAssociations (
association_id INT PRIMARY KEY,
student_id INT,
class_id INT,
FOREIGN KEY (student_id) REFERENCES Students(student_id),
FOREIGN KEY (class_id) REFERENCES Classes(class_id)
);
Output
SELECT COUNT(*)
FROM Teachers t
JOIN Classes c ON t.teacher_id = c.teacher_id
GROUP BY t.teacher_id
HAVING COUNT(c.class_id) = 1;