richardr1126 commited on
Commit
8a85885
β€’
1 Parent(s): e38b480
Files changed (1) hide show
  1. app-ngrok.py +11 -7
app-ngrok.py CHANGED
@@ -33,11 +33,13 @@ def format(text):
33
 
34
  return final_query_markdown
35
 
36
- def generate(input_message: str, db_info="", temperature=0.5, top_p=0.9, top_k=0, repetition_penalty=1.08, format_sql=True, stop_sequence="###,Explanation"):
37
  # Format the user's input message
38
  messages = f"Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\n\nConvert text to sql: {input_message} {db_info}\n\n### Response:\n\n"
39
 
40
  url = "https://e9f4be879d38-8269039109365193683.ngrok-free.app/api/v1/generate"
 
 
41
  payload = {
42
  "prompt": messages,
43
  "temperature": temperature,
@@ -46,10 +48,10 @@ def generate(input_message: str, db_info="", temperature=0.5, top_p=0.9, top_k=0
46
  "top_a": 0,
47
  "n": 1,
48
  "max_context_length": 2048,
49
- "max_length": 512,
50
  "rep_pen": repetition_penalty,
51
  "sampler_order": [6,0,1,3,4,2,5],
52
- "stop_sequence": stop_sequence.split(",").append("###"),
53
  }
54
  headers = {
55
  "Content-Type": "application/json",
@@ -76,7 +78,7 @@ def generate(input_message: str, db_info="", temperature=0.5, top_p=0.9, top_k=0
76
 
77
  # Gradio UI Code
78
  with gr.Blocks(theme='gradio/soft') as demo:
79
- # Elements stack vertically by default just define variables in order you want them to stack
80
  header = gr.HTML("""
81
  <h1 style="text-align: center">SQL Skeleton WizardCoder Demo</h1>
82
  <h3 style="text-align: center">πŸ•·οΈβ˜ οΈπŸ§™β€β™‚οΈ Generate SQL queries from Natural Language πŸ•·οΈβ˜ οΈπŸ§™β€β™‚οΈ</h3>
@@ -88,14 +90,16 @@ with gr.Blocks(theme='gradio/soft') as demo:
88
  db_info = gr.Textbox(lines=4, placeholder='Example: | table_01 : column_01 , column_02 | table_02 : column_01 , column_02 | ...', label='Database Info')
89
 
90
  with gr.Accordion("Options", open=False):
91
- temperature = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.5, step=0.1)
92
  top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.0, maximum=1.0, value=0.9, step=0.01)
93
  top_k = gr.Slider(label="Top-k", minimum=0, maximum=200, value=0, step=1)
94
  repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, value=1.08, step=0.01)
95
  format_sql = gr.Checkbox(label="Format SQL + Remove Skeleton", value=True, interactive=True)
96
- stop_sequence = gr.Textbox(lines=1, value="Explanation,Results,Note", label='Extra Stop Sequence')
97
-
 
98
  run_button = gr.Button("Generate SQL", variant="primary")
 
99
  run_button.click(fn=generate, inputs=[input_text, db_info, temperature, top_p, top_k, repetition_penalty, format_sql, stop_sequence], outputs=output_box, api_name="txt2sql")
100
 
101
  info = gr.HTML(f"""
 
33
 
34
  return final_query_markdown
35
 
36
+ def generate(input_message: str, db_info="", temperature=0.3, top_p=0.9, top_k=0, repetition_penalty=1.08, format_sql=True, stop_sequence="###"):
37
  # Format the user's input message
38
  messages = f"Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\n\nConvert text to sql: {input_message} {db_info}\n\n### Response:\n\n"
39
 
40
  url = "https://e9f4be879d38-8269039109365193683.ngrok-free.app/api/v1/generate"
41
+ stop_sequence = stop_sequence.split(",")
42
+ stop = ["###"] + stop_sequence
43
  payload = {
44
  "prompt": messages,
45
  "temperature": temperature,
 
48
  "top_a": 0,
49
  "n": 1,
50
  "max_context_length": 2048,
51
+ "max_length": 256,
52
  "rep_pen": repetition_penalty,
53
  "sampler_order": [6,0,1,3,4,2,5],
54
+ "stop_sequence": stop,
55
  }
56
  headers = {
57
  "Content-Type": "application/json",
 
78
 
79
  # Gradio UI Code
80
  with gr.Blocks(theme='gradio/soft') as demo:
81
+ # Elements stack vertically by default just define elements in order you want them to stack
82
  header = gr.HTML("""
83
  <h1 style="text-align: center">SQL Skeleton WizardCoder Demo</h1>
84
  <h3 style="text-align: center">πŸ•·οΈβ˜ οΈπŸ§™β€β™‚οΈ Generate SQL queries from Natural Language πŸ•·οΈβ˜ οΈπŸ§™β€β™‚οΈ</h3>
 
90
  db_info = gr.Textbox(lines=4, placeholder='Example: | table_01 : column_01 , column_02 | table_02 : column_01 , column_02 | ...', label='Database Info')
91
 
92
  with gr.Accordion("Options", open=False):
93
+ temperature = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.3, step=0.1)
94
  top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.0, maximum=1.0, value=0.9, step=0.01)
95
  top_k = gr.Slider(label="Top-k", minimum=0, maximum=200, value=0, step=1)
96
  repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, value=1.08, step=0.01)
97
  format_sql = gr.Checkbox(label="Format SQL + Remove Skeleton", value=True, interactive=True)
98
+ stop_sequence = gr.Textbox(lines=1, value="Explanation,Note", label='Extra Stop Sequence')
99
+
100
+ # Generate button UI element
101
  run_button = gr.Button("Generate SQL", variant="primary")
102
+ # When the button is clicked, call the generate function, inputs are taken from the UI elements, outputs are sent to outputs elements
103
  run_button.click(fn=generate, inputs=[input_text, db_info, temperature, top_p, top_k, repetition_penalty, format_sql, stop_sequence], outputs=output_box, api_name="txt2sql")
104
 
105
  info = gr.HTML(f"""