Spaces:
Sleeping
Sleeping
Commit
·
9699e75
1
Parent(s):
3c698c1
Test
Browse files
app.py
CHANGED
|
@@ -17,62 +17,7 @@ def respond(
|
|
| 17 |
temperature,
|
| 18 |
top_p,
|
| 19 |
):
|
| 20 |
-
|
| 21 |
-
### Instructions:
|
| 22 |
-
Your task is to convert a question into a SQL query, given a Postgres database schema.
|
| 23 |
-
Adhere to these rules:
|
| 24 |
-
- **Deliberately go through the question and database schema word by word** to appropriately answer the question
|
| 25 |
-
- **Use Table Aliases** to prevent ambiguity. For example, `SELECT table1.col1, table2.col1 FROM table1 JOIN table2 ON table1.id = table2.id`.
|
| 26 |
-
- When creating a ratio, always cast the numerator as float
|
| 27 |
-
|
| 28 |
-
### Input:
|
| 29 |
-
Generate a SQL query that answers the question `{question}`.
|
| 30 |
-
This query will run on a database whose schema is represented in this string:
|
| 31 |
-
CREATE TABLE products (
|
| 32 |
-
product_id INTEGER PRIMARY KEY, -- Unique ID for each product
|
| 33 |
-
name VARCHAR(50), -- Name of the product
|
| 34 |
-
price DECIMAL(10,2), -- Price of each unit of the product
|
| 35 |
-
quantity INTEGER -- Current quantity in stock
|
| 36 |
-
);
|
| 37 |
-
|
| 38 |
-
CREATE TABLE customers (
|
| 39 |
-
customer_id INTEGER PRIMARY KEY, -- Unique ID for each customer
|
| 40 |
-
name VARCHAR(50), -- Name of the customer
|
| 41 |
-
address VARCHAR(100) -- Mailing address of the customer
|
| 42 |
-
);
|
| 43 |
-
|
| 44 |
-
CREATE TABLE salespeople (
|
| 45 |
-
salesperson_id INTEGER PRIMARY KEY, -- Unique ID for each salesperson
|
| 46 |
-
name VARCHAR(50), -- Name of the salesperson
|
| 47 |
-
region VARCHAR(50) -- Geographic sales region
|
| 48 |
-
);
|
| 49 |
-
|
| 50 |
-
CREATE TABLE sales (
|
| 51 |
-
sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
|
| 52 |
-
product_id INTEGER, -- ID of product sold
|
| 53 |
-
customer_id INTEGER, -- ID of customer who made purchase
|
| 54 |
-
salesperson_id INTEGER, -- ID of salesperson who made the sale
|
| 55 |
-
sale_date DATE, -- Date the sale occurred
|
| 56 |
-
quantity INTEGER -- Quantity of product sold
|
| 57 |
-
);
|
| 58 |
-
|
| 59 |
-
CREATE TABLE product_suppliers (
|
| 60 |
-
supplier_id INTEGER PRIMARY KEY, -- Unique ID for each supplier
|
| 61 |
-
product_id INTEGER, -- Product ID supplied
|
| 62 |
-
supply_price DECIMAL(10,2) -- Unit price charged by supplier
|
| 63 |
-
);
|
| 64 |
-
|
| 65 |
-
-- sales.product_id can be joined with products.product_id
|
| 66 |
-
-- sales.customer_id can be joined with customers.customer_id
|
| 67 |
-
-- sales.salesperson_id can be joined with salespeople.salesperson_id
|
| 68 |
-
-- product_suppliers.product_id can be joined with products.product_id
|
| 69 |
-
|
| 70 |
-
### Response:
|
| 71 |
-
Based on your instructions, here is the SQL query I have generated to answer the question `{question}`:
|
| 72 |
-
```sql
|
| 73 |
-
"""
|
| 74 |
-
|
| 75 |
-
messages = [{"role": "system", "content": sytems}]
|
| 76 |
|
| 77 |
for val in history:
|
| 78 |
if val[0]:
|
|
@@ -103,7 +48,58 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 103 |
demo = gr.ChatInterface(
|
| 104 |
respond,
|
| 105 |
additional_inputs=[
|
| 106 |
-
gr.Textbox(value="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 108 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 109 |
gr.Slider(
|
|
|
|
| 17 |
temperature,
|
| 18 |
top_p,
|
| 19 |
):
|
| 20 |
+
messages = [{"role": "system", "content": system_message}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
for val in history:
|
| 23 |
if val[0]:
|
|
|
|
| 48 |
demo = gr.ChatInterface(
|
| 49 |
respond,
|
| 50 |
additional_inputs=[
|
| 51 |
+
gr.Textbox(value="""
|
| 52 |
+
### Instructions:
|
| 53 |
+
Your task is to convert a question into a SQL query, given a Postgres database schema.
|
| 54 |
+
Adhere to these rules:
|
| 55 |
+
- Use Table Aliases to prevent ambiguity.
|
| 56 |
+
- When creating a ratio, always cast the numerator as float.
|
| 57 |
+
|
| 58 |
+
### Input:
|
| 59 |
+
Generate a SQL query that answers the question `{question}`.
|
| 60 |
+
This query will run on a database whose schema is represented in this string:
|
| 61 |
+
CREATE TABLE products (
|
| 62 |
+
product_id INTEGER PRIMARY KEY, -- Unique ID for each product
|
| 63 |
+
name VARCHAR(50), -- Name of the product
|
| 64 |
+
price DECIMAL(10,2), -- Price of each unit of the product
|
| 65 |
+
quantity INTEGER -- Current quantity in stock
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
CREATE TABLE customers (
|
| 69 |
+
customer_id INTEGER PRIMARY KEY, -- Unique ID for each customer
|
| 70 |
+
name VARCHAR(50), -- Name of the customer
|
| 71 |
+
address VARCHAR(100) -- Mailing address of the customer
|
| 72 |
+
);
|
| 73 |
+
|
| 74 |
+
CREATE TABLE salespeople (
|
| 75 |
+
salesperson_id INTEGER PRIMARY KEY, -- Unique ID for each salesperson
|
| 76 |
+
name VARCHAR(50), -- Name of the salesperson
|
| 77 |
+
region VARCHAR(50) -- Geographic sales region
|
| 78 |
+
);
|
| 79 |
+
|
| 80 |
+
CREATE TABLE sales (
|
| 81 |
+
sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
|
| 82 |
+
product_id INTEGER, -- ID of product sold
|
| 83 |
+
customer_id INTEGER, -- ID of customer who made purchase
|
| 84 |
+
salesperson_id INTEGER, -- ID of salesperson who made the sale
|
| 85 |
+
sale_date DATE, -- Date the sale occurred
|
| 86 |
+
quantity INTEGER -- Quantity of product sold
|
| 87 |
+
);
|
| 88 |
+
|
| 89 |
+
CREATE TABLE product_suppliers (
|
| 90 |
+
supplier_id INTEGER PRIMARY KEY, -- Unique ID for each supplier
|
| 91 |
+
product_id INTEGER, -- Product ID supplied
|
| 92 |
+
supply_price DECIMAL(10,2) -- Unit price charged by supplier
|
| 93 |
+
);
|
| 94 |
+
|
| 95 |
+
-- sales.product_id can be joined with products.product_id
|
| 96 |
+
-- sales.customer_id can be joined with customers.customer_id
|
| 97 |
+
-- sales.salesperson_id can be joined with salespeople.salesperson_id
|
| 98 |
+
-- product_suppliers.product_id can be joined with products.product_id
|
| 99 |
+
|
| 100 |
+
### Response:
|
| 101 |
+
```sql
|
| 102 |
+
""", label="System message"),
|
| 103 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 104 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 105 |
gr.Slider(
|