Skip to content

A web-based application that converts natural language questions into SQL queries and executes them against SQLite databases.

License

Notifications You must be signed in to change notification settings

mostaphaelansari/Text-to-SQL-with-Deepseek

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text to SQL with Deepseek

Python SQLite Pandas Gradio

A web-based application that converts natural language questions into SQL queries and executes them against SQLite databases.

Features

  • Natural language to SQL query conversion
  • SQLite database connection and schema analysis
  • Query execution with result display
  • Conversation history tracking
  • Sample database creation for testing
  • Direct SQL query execution interface

Requirements

Python Version

Core Dependencies:

  • SQLite
  • Pandas
  • LangChain
  • LangChain Ollama
  • Gradio

Installation

  1. Clone the repository
  2. Install dependencies:
pip install pandas langchain-core langchain-ollama gradio
  1. Ensure Ollama is installed and running with the deepseek-coder model:
ollama pull deepseek-coder:6.7b

Usage

Starting the Application

python app.py

The application will launch in your web browser at http://localhost:7860

Database Connection

  1. Upload a SQLite database file (.db, .sqlite, .sqlite3)
  2. Or create a sample e-commerce database for testing

Querying Data

Submit questions in natural language through the Query Interface:

  • "Show all customers from USA"
  • "List top 5 products by sales"
  • "Find orders over $500"

Direct SQL Execution

Use the SQL Executor tab to run custom SQL queries directly against the connected database.

Configuration

The application uses the deepseek-coder:6.7b model by default. To change the model:

app = TextToSQLApp(model_name="your-preferred-model")

Sample Database Schema

The application can generate a sample e-commerce database with the following tables:

  • customers - Customer information
  • products - Product catalog
  • orders - Order records
  • order_items - Order line items

Limitations

  • Supports SQLite databases only
  • Requires Ollama runtime with compatible language models
  • Query complexity depends on model capabilities
  • No authentication or user management

Architecture

Architecture

  • Backend: Python with LangChain for LLM integration
  • Database: SQLite with Pandas for data handling
  • Frontend: Gradio web interface
  • LLM: Ollama compatible models for SQL generation

Error Handling

The application includes error handling for:

  • Database connection failures
  • Invalid SQL syntax
  • Missing database schema
  • Model communication errors

About

A web-based application that converts natural language questions into SQL queries and executes them against SQLite databases.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages