{"id":22506166,"url":"https://github.com/mdarshad1000/text-2-sql","last_synced_at":"2026-04-18T06:31:12.027Z","repository":{"id":264933708,"uuid":"868684685","full_name":"mdarshad1000/Text-2-SQL","owner":"mdarshad1000","description":"Query your SQL database using Natural Language! 🪄","archived":false,"fork":false,"pushed_at":"2024-12-03T01:32:00.000Z","size":172,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-18T08:52:49.526Z","etag":null,"topics":["docker","ollama","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mdarshad1000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-07T01:50:48.000Z","updated_at":"2024-12-03T01:32:04.000Z","dependencies_parsed_at":"2024-11-26T21:46:18.910Z","dependency_job_id":null,"html_url":"https://github.com/mdarshad1000/Text-2-SQL","commit_stats":null,"previous_names":["mdarshad1000/text-2-sql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mdarshad1000/Text-2-SQL","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdarshad1000%2FText-2-SQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdarshad1000%2FText-2-SQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdarshad1000%2FText-2-SQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdarshad1000%2FText-2-SQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdarshad1000","download_url":"https://codeload.github.com/mdarshad1000/Text-2-SQL/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdarshad1000%2FText-2-SQL/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31959873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","ollama","postgresql"],"created_at":"2024-12-07T00:41:21.807Z","updated_at":"2026-04-18T06:31:12.008Z","avatar_url":"https://github.com/mdarshad1000.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🤖 Natural Language to SQL Query Generator\n\nA Streamlit app that converts English questions into SQL queries using AI models. Simply ask questions about your data and get instant results!\n\n## 🚀 Quick Setup\n\n1. Clone and navigate to the project:\n```bash\ngit clone git@github.com:mdarshad1000/Text-2-SQL.git\ncd git@github.com:mdarshad1000/Text-2-SQL.git\n```\n\n2. Create `.env` file with your API keys:\n```env\nOPENAI_API_KEY=your_key_here\nGEMINI_API_KEY=your_key_here\n```\n\n3. Start the app:\n```bash\ndocker compose up -d\n```\n\nVisit `http://0.0.0.0:8501` in your browser.\n\n## 💡 How to Use\n\n1. Select an AI model (GPT-4, Llama3.2:latest, or Gemini)\n{{ If you want to use the Llama3.2 model, ensure the Ollama server is running. }}\n2. Type your question (e.g., \"Show me all sales from last month\")\n3. Click \"Generate Results\"\n4. View your data in tables or charts\n5. Download results as CSV if needed\n\n## 🏗️ Code Structure \u0026 Documentation\n\n\n### Folder Structure\n\n```\n`Chinook_PostgreSql.sql`: SQL script to create database schema\n`Dockerfile`: Docker file to build Docker image\n`README.md`: This README file\n`app.py`: Main application file\n`config.py`: Configuration file for LLM models\n`docker-compose.yml`: Docker Compose file to run Docker image\n`llm_integration.py`: Abstract base class for LLM integrations\n`query_executor.py`: Database executor class\n`requirements.txt`: Python dependencies\n```\n\n### Classes\n\n#### `LLMQueryGenerator` (Abstract Base Class)\nBase class for all AI model integrations.\n- `generate_sql_from_nl(db_schema, nl_query)`: Abstract method to convert natural language to SQL\n\n#### `OpenAIQueryGenerator`\nHandles GPT-4 integration.\n- `__init__(model, sys_prompt, user_prompt)`: Initializes with model settings\n- `generate_sql_from_nl(db_schema, nl_query)`: Generates SQL using OpenAI API\n\n#### `OllamaQueryGenerator`\nManages Llama3.2:latest integration.\n- `__init__(model, sys_prompt, user_prompt)`: Sets up Ollama configuration\n- `generate_sql_from_nl(db_schema, nl_query)`: Generates SQL using Ollama\n\n#### `GeminiQueryGenerator`\nHandles Google's Gemini integration.\n- `__init__(model, sys_prompt, user_prompt)`: Configures Gemini settings\n- `generate_sql_from_nl(db_schema, nl_query)`: Generates SQL using Gemini API\n\n#### `DatabaseExecutor`\nManages database operations.\n- `connect()`: Establishes database connection\n- `disconnect()`: Closes database connection\n- `execute_query(query)`: Runs SQL queries and returns results as DataFrame\n- `get_schema_info()`: Returns database structure information\n\n### Workflow\n\n1. **Initialization**\n   - App starts and creates `DatabaseExecutor` instance\n   - Initializes AI models (GPT-4, Llama3.2, Gemini)\n\n2. **User Interaction**\n   - User selects AI model\n   - Views database schema\n   - Enters natural language question\n\n3. **Query Processing**\n   ```\n   User Question → AI Model → SQL Query → Database → Results → Visualization\n   ```\n\n4. **Data Display**\n   - Results shown in table format\n   - Optional visualization in charts\n   - CSV export available\n\n## 🛠️ Troubleshooting\n\nIf something's not working:\n1. Check container status: `docker compose ps`\n2. View logs: `docker compose logs app`\n3. Restart if needed: `docker compose restart`\n\n## 📝 Notes\n\n- Uses Chinook sample database (digital media store data)\n- Supports basic data visualization\n- Downloads available in CSV format\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdarshad1000%2Ftext-2-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdarshad1000%2Ftext-2-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdarshad1000%2Ftext-2-sql/lists"}