Spaces:
Sleeping
Sleeping
Commit
·
39917e3
1
Parent(s):
75823b9
Test
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
| 7 |
-
client = InferenceClient("
|
| 8 |
|
| 9 |
|
| 10 |
def respond(
|
|
@@ -15,7 +15,61 @@ def respond(
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
for val in history:
|
| 21 |
if val[0]:
|
|
@@ -46,7 +100,6 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 46 |
demo = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
gr.Slider(
|
|
|
|
| 4 |
"""
|
| 5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
"""
|
| 7 |
+
client = InferenceClient("Qwen/Qwen2.5-Coder-7B-Instruct")
|
| 8 |
|
| 9 |
|
| 10 |
def respond(
|
|
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
| 18 |
+
sytems = """
|
| 19 |
+
### Instructions:
|
| 20 |
+
Your task is to convert a question into a SQL query, given a Postgres database schema.
|
| 21 |
+
Adhere to these rules:
|
| 22 |
+
- **Deliberately go through the question and database schema word by word** to appropriately answer the question
|
| 23 |
+
- **Use Table Aliases** to prevent ambiguity. For example, `SELECT table1.col1, table2.col1 FROM table1 JOIN table2 ON table1.id = table2.id`.
|
| 24 |
+
- When creating a ratio, always cast the numerator as float
|
| 25 |
+
|
| 26 |
+
### Input:
|
| 27 |
+
Generate a SQL query that answers the question `{question}`.
|
| 28 |
+
This query will run on a database whose schema is represented in this string:
|
| 29 |
+
CREATE TABLE products (
|
| 30 |
+
product_id INTEGER PRIMARY KEY, -- Unique ID for each product
|
| 31 |
+
name VARCHAR(50), -- Name of the product
|
| 32 |
+
price DECIMAL(10,2), -- Price of each unit of the product
|
| 33 |
+
quantity INTEGER -- Current quantity in stock
|
| 34 |
+
);
|
| 35 |
+
|
| 36 |
+
CREATE TABLE customers (
|
| 37 |
+
customer_id INTEGER PRIMARY KEY, -- Unique ID for each customer
|
| 38 |
+
name VARCHAR(50), -- Name of the customer
|
| 39 |
+
address VARCHAR(100) -- Mailing address of the customer
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
CREATE TABLE salespeople (
|
| 43 |
+
salesperson_id INTEGER PRIMARY KEY, -- Unique ID for each salesperson
|
| 44 |
+
name VARCHAR(50), -- Name of the salesperson
|
| 45 |
+
region VARCHAR(50) -- Geographic sales region
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
CREATE TABLE sales (
|
| 49 |
+
sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
|
| 50 |
+
product_id INTEGER, -- ID of product sold
|
| 51 |
+
customer_id INTEGER, -- ID of customer who made purchase
|
| 52 |
+
salesperson_id INTEGER, -- ID of salesperson who made the sale
|
| 53 |
+
sale_date DATE, -- Date the sale occurred
|
| 54 |
+
quantity INTEGER -- Quantity of product sold
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
CREATE TABLE product_suppliers (
|
| 58 |
+
supplier_id INTEGER PRIMARY KEY, -- Unique ID for each supplier
|
| 59 |
+
product_id INTEGER, -- Product ID supplied
|
| 60 |
+
supply_price DECIMAL(10,2) -- Unit price charged by supplier
|
| 61 |
+
);
|
| 62 |
+
|
| 63 |
+
-- sales.product_id can be joined with products.product_id
|
| 64 |
+
-- sales.customer_id can be joined with customers.customer_id
|
| 65 |
+
-- sales.salesperson_id can be joined with salespeople.salesperson_id
|
| 66 |
+
-- product_suppliers.product_id can be joined with products.product_id
|
| 67 |
+
|
| 68 |
+
### Response:
|
| 69 |
+
Based on your instructions, here is the SQL query I have generated to answer the question `{question}`:
|
| 70 |
+
```sql
|
| 71 |
+
"""
|
| 72 |
+
messages = [{"role": "system", "content": sytems}]
|
| 73 |
|
| 74 |
for val in history:
|
| 75 |
if val[0]:
|
|
|
|
| 100 |
demo = gr.ChatInterface(
|
| 101 |
respond,
|
| 102 |
additional_inputs=[
|
|
|
|
| 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(
|