onkolahmet commited on
Commit
140471a
·
verified ·
1 Parent(s): 850c4bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -7,31 +7,31 @@ import sqlparse
7
  # Load model and tokenizer
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
  model = AutoModelForCausalLM.from_pretrained(
10
- "onkolahmet/text_to_sql",
11
  torch_dtype="auto",
12
  device_map="auto"
13
  )
14
- tokenizer = AutoTokenizer.from_pretrained("onkolahmet/text_to_sql")
15
 
16
- # Few-shot examples to include in each prompt
17
- examples = [
18
- {
19
- "question": "Get the names and emails of customers who placed an order in the last 30 days.",
20
- "sql": "SELECT name, email FROM customers WHERE order_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY);"
21
- },
22
- {
23
- "question": "Find all employees with a salary greater than 50000.",
24
- "sql": "SELECT * FROM employees WHERE salary > 50000;"
25
- },
26
- {
27
- "question": "List all product names and their categories where the price is below 50.",
28
- "sql": "SELECT name, category FROM products WHERE price < 50;"
29
- },
30
- {
31
- "question": "How many users registered in the year 2022?",
32
- "sql": "SELECT COUNT(*) FROM users WHERE YEAR(registration_date) = 2022;"
33
- }
34
- ]
35
 
36
  def generate_sql(question, context=None):
37
  # Construct prompt with few-shot examples and context if available
@@ -41,9 +41,9 @@ def generate_sql(question, context=None):
41
  if context and context.strip():
42
  prompt += f"Table Context:\n{context}\n\n"
43
 
44
- # Add few-shot examples
45
- for ex in examples:
46
- prompt += f"Q: {ex['question']}\nSQL: {ex['sql']}\n\n"
47
 
48
  # Add the current question
49
  prompt += f"Q: {question}\nSQL:"
@@ -297,7 +297,7 @@ with gr.Blocks(title="Text to SQL Converter") as demo:
297
  ### About
298
  This app uses a fine-tuned language model to convert natural language questions into SQL queries.
299
 
300
- - **Model**: [onkolahmet/text_to_sql](https://huggingface.co/onkolahmet/text_to_sql)
301
  - **How to use**:
302
  1. Enter your question in natural language
303
  2. If you have specific table schemas, add them in the Table Context field
 
7
  # Load model and tokenizer
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
  model = AutoModelForCausalLM.from_pretrained(
10
+ "onkolahmet/Qwen2-0.5B-Instruct-SQL-generator",
11
  torch_dtype="auto",
12
  device_map="auto"
13
  )
14
+ tokenizer = AutoTokenizer.from_pretrained("onkolahmet/Qwen2-0.5B-Instruct-SQL-generator")
15
 
16
+ # # Few-shot examples to include in each prompt
17
+ # examples = [
18
+ # {
19
+ # "question": "Get the names and emails of customers who placed an order in the last 30 days.",
20
+ # "sql": "SELECT name, email FROM customers WHERE order_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY);"
21
+ # },
22
+ # {
23
+ # "question": "Find all employees with a salary greater than 50000.",
24
+ # "sql": "SELECT * FROM employees WHERE salary > 50000;"
25
+ # },
26
+ # {
27
+ # "question": "List all product names and their categories where the price is below 50.",
28
+ # "sql": "SELECT name, category FROM products WHERE price < 50;"
29
+ # },
30
+ # {
31
+ # "question": "How many users registered in the year 2022?",
32
+ # "sql": "SELECT COUNT(*) FROM users WHERE YEAR(registration_date) = 2022;"
33
+ # }
34
+ # ]
35
 
36
  def generate_sql(question, context=None):
37
  # Construct prompt with few-shot examples and context if available
 
41
  if context and context.strip():
42
  prompt += f"Table Context:\n{context}\n\n"
43
 
44
+ # # Add few-shot examples
45
+ # for ex in examples:
46
+ # prompt += f"Q: {ex['question']}\nSQL: {ex['sql']}\n\n"
47
 
48
  # Add the current question
49
  prompt += f"Q: {question}\nSQL:"
 
297
  ### About
298
  This app uses a fine-tuned language model to convert natural language questions into SQL queries.
299
 
300
+ - **Model**: [onkolahmet/Qwen2-0.5B-Instruct-SQL-generator](https://huggingface.co/onkolahmet/Qwen2-0.5B-Instruct-SQL-generator)
301
  - **How to use**:
302
  1. Enter your question in natural language
303
  2. If you have specific table schemas, add them in the Table Context field