manuelaschrittwieser commited on
Commit
e30b198
Β·
verified Β·
1 Parent(s): 83dc110

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +105 -6
README.md CHANGED
@@ -1,17 +1,116 @@
1
  ---
2
- title: SQL Assistant Prod
3
- emoji: πŸ’¬
4
  colorFrom: yellow
5
  colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.42.0
8
  app_file: app.py
9
  pinned: false
 
 
10
  hf_oauth: true
11
  hf_oauth_scopes:
12
  - inference-api
13
- license: mit
14
- short_description: 'An autonomous SQL agent, based on Qwen 2.5 (fine-tuned). '
 
 
 
 
 
 
 
15
  ---
16
 
17
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Autonomous SQL Agent
3
+ emoji: πŸ’¬
4
  colorFrom: yellow
5
  colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 4.19.2
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
+ short_description: 'An autonomous SQL agent, based on Qwen 2.5 (fine-tuned). '
12
  hf_oauth: true
13
  hf_oauth_scopes:
14
  - inference-api
15
+ models:
16
+ - manuelaschrittwieser/Qwen2.5-1.5B-SQL-Assistant-Prod
17
+ - Qwen/Qwen2.5-1.5B-Instruct
18
+ tags:
19
+ - agent
20
+ - sql
21
+ - text-to-sql
22
+ - qwen
23
+ - qlora
24
  ---
25
 
26
+ # Autonomous SQL Assistant Agent
27
+
28
+ ## πŸ“‹ System Overview
29
+
30
+ The **Autonomous SQL Assistant** is a demonstrative AI agent designed to bridge the gap between natural language inquiries and database execution. Unlike standard "Text-to-SQL" generators that strictly output code, this agent operates within a closed-loop environment: it **generates** syntax, **executes** it against a live database, and **retrieves** the actual data for the user.
31
+
32
+ The system is powered by **Qwen 2.5 (1.5B)**, fine-tuned via **QLoRA** on the `b-mc2/sql-create-context` dataset to ensure high fidelity in SQL syntax generation.
33
+
34
+ **[πŸ”— View Source Code & Documentation](https://github.com/MANU-de/Autonomous-SQL-Agent)**
35
+
36
+ ---
37
+
38
+ ## πŸ—οΈ Technical Architecture
39
+
40
+ The application runs on a lightweight CPU environment and consists of three core components:
41
+
42
+ ### 1. The Inference Engine
43
+ * **Model:** [manuelaschrittwieser/Qwen2.5-1.5B-SQL-Assistant-Prod](https://huggingface.co/manuelaschrittwieser/Qwen2.5-1.5B-SQL-Assistant-Prod)
44
+ * **Optimization:** The model runs in full FP32 precision (CPU optimized).
45
+ * **Role:** Translates user intent (e.g., *"Who earns the most?"*) into executable SQLite syntax, utilizing the provided schema context.
46
+
47
+ ### 2. The Execution Sandbox
48
+ * **Database:** A transient **SQLite** instance.
49
+ * **Schema:** `employees` (id, name, department, salary, hire_date).
50
+ * **Lifecycle:** The database is re-instantiated upon every application restart/build to ensure a clean state for testing.
51
+
52
+ ### 3. The Agent Logic
53
+ The `SQLAgent` class orchestrates the workflow:
54
+ 1. **Ingest:** Receives natural language prompt.
55
+ 2. **Contextualize:** Injects the `CREATE TABLE` schema into the system prompt.
56
+ 3. **Generate:** produces the SQL query.
57
+ 4. **Act:** Connects to the SQLite cursor, executes the query, and fetches results.
58
+ 5. **Sanitize:** Catches execution errors (e.g., syntax errors) and reports them for debugging.
59
+
60
+ ---
61
+
62
+ ## πŸ’» Usage Instructions
63
+
64
+ ### Interface Guide
65
+ The interface is a chat-based UI. You act as the user querying the HR database.
66
+
67
+ * **Input:** Type natural language questions regarding the `employees` table.
68
+ * **Output:** The agent provides a two-part response:
69
+ 1. **"Brain" (Internal Monologue):** The generated SQL query.
70
+ 2. **"Result" (Data):** The raw tuples returned from the database.
71
+
72
+ ### Example Queries
73
+ Try copying these prompts to test the agent's capabilities:
74
+
75
+ | Complexity | Query |
76
+ | :--- | :--- |
77
+ | **Simple** | *Show me the names of all employees in Sales.* |
78
+ | **Conditional** | *Who earns more than 60000?* |
79
+ | **Aggregation** | *Count how many employees work in the Engineering department.* |
80
+ | **Logic** | *List employees hired after 2020.* |
81
+
82
+ ---
83
+
84
+ ## βš™οΈ Local Reproduction
85
+
86
+ To run this Space locally on your machine (requires Python 3.10+):
87
+
88
+ 1. **Clone the Repository:**
89
+ ```bash
90
+ git clone https://huggingface.co/spaces/manuelaschrittwieser/sql-assistant-prod
91
+ cd sql-assistant-prod
92
+ ```
93
+
94
+ 2. **Install Dependencies:**
95
+ ```bash
96
+ pip install -r requirements.txt
97
+ ```
98
+
99
+ 3. **Launch Application:**
100
+ ```bash
101
+ python app.py
102
+ ```
103
+
104
+ ---
105
+
106
+ ## ⚠️ Limitations & Scope
107
+
108
+ * **Inference Latency:** As this demo runs on **CPU Basic** hardware, generating the SQL query may take 2-10 seconds depending on server load.
109
+ * **Sandbox Restrictions:** Database modifications (INSERT/DROP) are possible but will persist only until the application restarts.
110
+ * **Hallucinations:** While fine-tuned, the model may occasionally generate invalid SQL for highly complex queries not covered in the training distribution.
111
+
112
+ ---
113
+
114
+ ## πŸ“œ License
115
+
116
+ This project is open-source and available under the **MIT License**.