Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,174 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
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("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
|
10 |
-
def respond(
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
):
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
|
41 |
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
"""
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
|
|
|
|
62 |
|
63 |
-
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
# from huggingface_hub import InferenceClient
|
3 |
|
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("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
|
10 |
+
# def respond(
|
11 |
+
# message,
|
12 |
+
# history: list[tuple[str, str]],
|
13 |
+
# system_message,
|
14 |
+
# max_tokens,
|
15 |
+
# temperature,
|
16 |
+
# top_p,
|
17 |
+
# ):
|
18 |
+
# messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
+
# for val in history:
|
21 |
+
# if val[0]:
|
22 |
+
# messages.append({"role": "user", "content": val[0]})
|
23 |
+
# if val[1]:
|
24 |
+
# messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
+
# messages.append({"role": "user", "content": message})
|
27 |
|
28 |
+
# response = ""
|
29 |
|
30 |
+
# for message in client.chat_completion(
|
31 |
+
# messages,
|
32 |
+
# max_tokens=max_tokens,
|
33 |
+
# stream=True,
|
34 |
+
# temperature=temperature,
|
35 |
+
# top_p=top_p,
|
36 |
+
# ):
|
37 |
+
# token = message.choices[0].delta.content
|
38 |
|
39 |
+
# response += token
|
40 |
+
# yield response
|
41 |
|
42 |
|
43 |
+
# """
|
44 |
+
# For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
+
# """
|
46 |
+
# demo = gr.ChatInterface(
|
47 |
+
# respond,
|
48 |
+
# additional_inputs=[
|
49 |
+
# gr.Textbox(value="You are a friendly SQL 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(
|
53 |
+
# minimum=0.1,
|
54 |
+
# maximum=1.0,
|
55 |
+
# value=0.95,
|
56 |
+
# step=0.05,
|
57 |
+
# label="Top-p (nucleus sampling)",
|
58 |
+
# ),
|
59 |
+
# ],
|
60 |
+
# )
|
61 |
+
|
62 |
+
|
63 |
+
# if __name__ == "__main__":
|
64 |
+
# demo.launch()
|
65 |
+
|
66 |
+
# Import necessary libraries
|
67 |
+
import gradio as gr
|
68 |
+
|
69 |
+
# Define the prompt template
|
70 |
+
odoo_text2sql_prompt = """
|
71 |
+
Instruction: {instruction}
|
72 |
+
Input: {input_text}
|
73 |
+
Output: {output_text}
|
74 |
+
DB Schema: {db_schema}
|
75 |
"""
|
76 |
+
|
77 |
+
# Define the database schema
|
78 |
+
db_schema = """
|
79 |
+
CREATE TABLE product_product (
|
80 |
+
id SERIAL NOT NULL,
|
81 |
+
message_main_attachment_id INTEGER,
|
82 |
+
product_tmpl_id INTEGER NOT NULL,
|
83 |
+
create_uid INTEGER,
|
84 |
+
write_uid INTEGER,
|
85 |
+
default_code VARCHAR,
|
86 |
+
barcode VARCHAR,
|
87 |
+
combination_indices VARCHAR,
|
88 |
+
volume NUMERIC,
|
89 |
+
weight NUMERIC,
|
90 |
+
active BOOLEAN,
|
91 |
+
can_image_variant_1024_be_zoomed BOOLEAN,
|
92 |
+
create_date TIMESTAMP WITHOUT TIME ZONE,
|
93 |
+
write_date TIMESTAMP WITHOUT TIME ZONE,
|
94 |
+
store_qty_available DOUBLE PRECISION,
|
95 |
+
store_standard_price DOUBLE PRECISION,
|
96 |
+
store_sales_count DOUBLE PRECISION,
|
97 |
+
CONSTRAINT product_product_pkey PRIMARY KEY (id),
|
98 |
+
CONSTRAINT product_product_create_uid_fkey FOREIGN KEY(create_uid) REFERENCES res_users (id) ON DELETE SET NULL,
|
99 |
+
CONSTRAINT product_product_message_main_attachment_id_fkey FOREIGN KEY(message_main_attachment_id) REFERENCES ir_attachment (id) ON DELETE SET NULL,
|
100 |
+
CONSTRAINT product_product_product_tmpl_id_fkey FOREIGN KEY(product_tmpl_id) REFERENCES product_template (id) ON DELETE CASCADE,
|
101 |
+
CONSTRAINT product_product_write_uid_fkey FOREIGN KEY(write_uid) REFERENCES res_users (id) ON DELETE SET NULL
|
102 |
)
|
103 |
+
"""
|
104 |
+
|
105 |
+
# Function to generate SQL query (placeholder function)
|
106 |
+
def generate_sql(instruction, input_text):
|
107 |
+
return "Model is not loaded. Please ensure you have the necessary GPU resources."
|
108 |
+
|
109 |
+
# Function to clear inputs
|
110 |
+
def clear_inputs():
|
111 |
+
return "", ""
|
112 |
+
|
113 |
+
# Create the Gradio interface with enhanced features
|
114 |
+
with gr.Blocks(css="""
|
115 |
+
.centered {
|
116 |
+
display: flex;
|
117 |
+
justify-content: center;
|
118 |
+
align-items: center;
|
119 |
+
text-align: center;
|
120 |
+
}
|
121 |
+
.title {
|
122 |
+
font-size: 2em;
|
123 |
+
font-weight: bold;
|
124 |
+
margin-bottom: 20px;
|
125 |
+
}
|
126 |
+
.description {
|
127 |
+
font-size: 1.2em;
|
128 |
+
margin-bottom: 20px;
|
129 |
+
}
|
130 |
+
.button {
|
131 |
+
background-color: #007BFF; /* Sea blue color */
|
132 |
+
color: white;
|
133 |
+
border: none;
|
134 |
+
padding: 10px 20px;
|
135 |
+
text-align: center;
|
136 |
+
text-decoration: none;
|
137 |
+
display: inline-block;
|
138 |
+
font-size: 16px;
|
139 |
+
margin: 4px 2px;
|
140 |
+
cursor: pointer;
|
141 |
+
border-radius: 12px;
|
142 |
+
}
|
143 |
+
.button:hover {
|
144 |
+
background-color: #0056b3;
|
145 |
+
}
|
146 |
+
""") as demo:
|
147 |
+
gr.Markdown('<div class="centered"><div class="title">DeepSQL AI Assistant</div></div>')
|
148 |
+
gr.Markdown('<div class="centered"><div class="description">Generate SQL queries for Database Schema based on Natural Language input.</div></div>')
|
149 |
+
|
150 |
+
with gr.Row():
|
151 |
+
with gr.Column():
|
152 |
+
instruction = gr.Textbox(lines=7, placeholder="Enter the instruction here...", label="Instruction")
|
153 |
+
input_text = gr.Textbox(lines=7, placeholder="Enter the input text here...", label="Input Text")
|
154 |
+
clear_button = gr.Button("Clear", elem_classes="button")
|
155 |
+
|
156 |
+
with gr.Column():
|
157 |
+
output = gr.Textbox(lines=15, placeholder="Generated SQL query will appear here...", label="Output SQL Query")
|
158 |
+
feedback = gr.Textbox(lines=2, placeholder="Provide your feedback here...", label="Feedback")
|
159 |
+
|
160 |
+
examples = gr.Examples(
|
161 |
+
examples=[
|
162 |
+
["Find the top 5 products with the highest sales count.", "What are the top sales products?"],
|
163 |
+
["List all active products.", "Show me all active products."],
|
164 |
+
],
|
165 |
+
inputs=[instruction, input_text]
|
166 |
+
)
|
167 |
+
|
168 |
+
submit_button = gr.Button("Generate SQL", elem_classes="button")
|
169 |
+
submit_button.click(generate_sql, inputs=[instruction, input_text], outputs=output)
|
170 |
+
clear_button.click(clear_inputs, outputs=[instruction, input_text])
|
171 |
|
172 |
+
# Launch the Gradio interface with sharing enabled
|
173 |
+
demo.launch(share=True)
|
174 |
|
|
|
|