richardr1126 commited on
Commit
d9f22f5
Β·
1 Parent(s): e64095c
Files changed (2) hide show
  1. app-ngrok.py +4 -4
  2. test.py +48 -26
app-ngrok.py CHANGED
@@ -126,18 +126,18 @@ with gr.Blocks(theme='gradio/soft') as demo:
126
  note = gr.HTML("""<p style="font-size: 12px; text-align: center">⚠️ Should take 30-60s to generate</p>""")
127
  input_text = gr.Textbox(lines=3, placeholder='Write your question here...', label='NL Input')
128
  db_info = gr.Textbox(lines=4, placeholder='Example: | table_01 : column_01 , column_02 | table_02 : column_01 , column_02 | ...', label='Database Info')
 
 
 
 
129
 
130
  with gr.Accordion("Options", open=False):
131
  temperature = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.2, step=0.1)
132
  top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.0, maximum=1.0, value=0.9, step=0.01)
133
  top_k = gr.Slider(label="Top-k", minimum=0, maximum=200, value=0, step=1)
134
  repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, value=1.08, step=0.01)
135
- format_sql = gr.Checkbox(label="Format SQL + Remove Skeleton", value=True, interactive=True)
136
  stop_sequence = gr.Textbox(lines=1, value="Explanation,Note", label='Extra Stop Sequence')
137
 
138
- # Generate button UI element
139
- run_button = gr.Button("Generate SQL", variant="primary")
140
-
141
  ## Add statement saying that inputs/outpus are sent to firebase
142
  info = gr.HTML(f"""
143
  <p>🌐 Leveraging the <a href='https://huggingface.co/{quantized_model}'><strong>4-bit GGML version</strong></a> of <a href='https://huggingface.co/{merged_model}'><strong>{merged_model}</strong></a> model.</p>
 
126
  note = gr.HTML("""<p style="font-size: 12px; text-align: center">⚠️ Should take 30-60s to generate</p>""")
127
  input_text = gr.Textbox(lines=3, placeholder='Write your question here...', label='NL Input')
128
  db_info = gr.Textbox(lines=4, placeholder='Example: | table_01 : column_01 , column_02 | table_02 : column_01 , column_02 | ...', label='Database Info')
129
+ format_sql = gr.Checkbox(label="Format SQL + Remove Skeleton", value=True, interactive=True)
130
+
131
+ # Generate button UI element
132
+ run_button = gr.Button("Generate SQL", variant="primary")
133
 
134
  with gr.Accordion("Options", open=False):
135
  temperature = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.2, step=0.1)
136
  top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.0, maximum=1.0, value=0.9, step=0.01)
137
  top_k = gr.Slider(label="Top-k", minimum=0, maximum=200, value=0, step=1)
138
  repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, value=1.08, step=0.01)
 
139
  stop_sequence = gr.Textbox(lines=1, value="Explanation,Note", label='Extra Stop Sequence')
140
 
 
 
 
141
  ## Add statement saying that inputs/outpus are sent to firebase
142
  info = gr.HTML(f"""
143
  <p>🌐 Leveraging the <a href='https://huggingface.co/{quantized_model}'><strong>4-bit GGML version</strong></a> of <a href='https://huggingface.co/{merged_model}'><strong>{merged_model}</strong></a> model.</p>
test.py CHANGED
@@ -1,52 +1,74 @@
1
  import gradio as gr
2
 
3
- def bot(input_message: str, db_info="", temperature=0.1, top_p=0.9, top_k=0, repetition_penalty=1.08):
4
  # For the stripped down version, let's just return a preset output
5
  final_query = "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"
6
  final_query_markdown = f"{final_query}"
7
  return final_query_markdown
8
 
 
9
  with gr.Blocks(theme='gradio/soft') as demo:
 
10
  header = gr.HTML("""
11
  <h1 style="text-align: center">SQL Skeleton WizardCoder Demo</h1>
12
- <h3 style="text-align: center">πŸ§™β€β™‚οΈ Generate SQL queries from Natural Language πŸ§™β€β™‚οΈ</h3>
13
  """)
14
 
15
  output_box = gr.Code(label="Generated SQL", lines=2, interactive=True)
 
16
  input_text = gr.Textbox(lines=3, placeholder='Write your question here...', label='NL Input')
17
  db_info = gr.Textbox(lines=4, placeholder='Example: | table_01 : column_01 , column_02 | table_02 : column_01 , column_02 | ...', label='Database Info')
 
 
 
 
18
 
19
- with gr.Accordion("Hyperparameters", open=False):
20
- temperature = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.5, step=0.1)
21
  top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.0, maximum=1.0, value=0.9, step=0.01)
22
  top_k = gr.Slider(label="Top-k", minimum=0, maximum=200, value=0, step=1)
23
  repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, value=1.08, step=0.01)
24
-
25
- run_button = gr.Button("Generate SQL", variant="primary")
26
 
27
- with gr.Accordion("Examples", open=True):
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  examples = gr.Examples([
29
- ["What is the average, minimum, and maximum age for all French singers?", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
 
 
30
  ["Show location and name for all stadiums with a capacity between 5000 and 10000.", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
31
  ["What are the number of concerts that occurred in the stadium with the largest capacity ?", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
32
- ["How many male singers performed in concerts in the year 2023?", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
33
- ["List the names of all singers who performed in a concert with the theme 'Rock'", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"]
34
- ], inputs=[input_text, db_info, temperature, top_p, top_k, repetition_penalty], fn=bot)
35
-
36
- bitsandbytes_model = "richardr1126/spider-skeleton-wizard-coder-8bit"
37
- merged_model = "richardr1126/spider-skeleton-wizard-coder-merged"
38
- initial_model = "WizardLM/WizardCoder-15B-V1.0"
39
- finetuned_model = "richardr1126/spider-skeleton-wizard-coder-qlora"
40
- dataset = "richardr1126/spider-skeleton-context-instruct"
41
-
42
- footer = gr.HTML(f"""
43
- <p>πŸ› οΈ If you want you can <strong>duplicate this Space</strong>, then change the HF_MODEL_REPO spaces env varaible to use any Transformers model.</p>
44
- <p>🌐 Leveraging the <a href='https://huggingface.co/{bitsandbytes_model}'><strong>bitsandbytes 8-bit version</strong></a> of <a href='https://huggingface.co/{merged_model}'><strong>{merged_model}</strong></a> model.</p>
45
- <p>πŸ”— How it's made: <a href='https://huggingface.co/{initial_model}'><strong>{initial_model}</strong></a> was finetuned to create <a href='https://huggingface.co/{finetuned_model}'><strong>{finetuned_model}</strong></a>, then merged together to create <a href='https://huggingface.co/{merged_model}'><strong>{merged_model}</strong></a>.</p>
46
- <p>πŸ“‰ Fine-tuning was performed using QLoRA techniques on the <a href='https://huggingface.co/datasets/{dataset}'><strong>{dataset}</strong></a> dataset. You can view training metrics on the <a href='https://huggingface.co/{finetuned_model}'><strong>QLoRa adapter HF Repo</strong></a>.</p>
47
- """)
48
 
 
 
49
 
50
- run_button.click(fn=bot, inputs=[input_text, db_info, temperature, top_p, top_k, repetition_penalty], outputs=output_box, api_name="txt2sql")
 
 
 
 
 
 
 
 
 
 
51
 
52
- demo.queue(concurrency_count=1, max_size=10).launch()
 
1
  import gradio as gr
2
 
3
+ def bot(input_message: str, db_info="", temperature=0.1, top_p=0.9, top_k=0, repetition_penalty=1.08, format_sql=True, stop_sequence="Explanation,Note", log=True):
4
  # For the stripped down version, let's just return a preset output
5
  final_query = "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"
6
  final_query_markdown = f"{final_query}"
7
  return final_query_markdown
8
 
9
+ # Gradio UI Code
10
  with gr.Blocks(theme='gradio/soft') as demo:
11
+ # Elements stack vertically by default just define elements in order you want them to stack
12
  header = gr.HTML("""
13
  <h1 style="text-align: center">SQL Skeleton WizardCoder Demo</h1>
14
+ <h3 style="text-align: center">πŸ•·οΈβ˜ οΈπŸ§™β€β™‚οΈ Generate SQL queries from Natural Language πŸ•·οΈβ˜ οΈπŸ§™β€β™‚οΈ</h3>
15
  """)
16
 
17
  output_box = gr.Code(label="Generated SQL", lines=2, interactive=True)
18
+ note = gr.HTML("""<p style="font-size: 12px; text-align: center">⚠️ Should take 30-60s to generate</p>""")
19
  input_text = gr.Textbox(lines=3, placeholder='Write your question here...', label='NL Input')
20
  db_info = gr.Textbox(lines=4, placeholder='Example: | table_01 : column_01 , column_02 | table_02 : column_01 , column_02 | ...', label='Database Info')
21
+ format_sql = gr.Checkbox(label="Format SQL + Remove Skeleton", value=True, interactive=True)
22
+
23
+ # Generate button UI element
24
+ run_button = gr.Button("Generate SQL", variant="primary")
25
 
26
+ with gr.Accordion("Options", open=False):
27
+ temperature = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.2, step=0.1)
28
  top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.0, maximum=1.0, value=0.9, step=0.01)
29
  top_k = gr.Slider(label="Top-k", minimum=0, maximum=200, value=0, step=1)
30
  repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, value=1.08, step=0.01)
31
+ stop_sequence = gr.Textbox(lines=1, value="Explanation,Note", label='Extra Stop Sequence')
 
32
 
33
+ ## Add statement saying that inputs/outpus are sent to firebase
34
+ info = gr.HTML(f"""
35
+ <p>🌐 Leveraging the <a href='https://huggingface.co/{quantized_model}'><strong>4-bit GGML version</strong></a> of <a href='https://huggingface.co/{merged_model}'><strong>{merged_model}</strong></a> model.</p>
36
+ <p>πŸ”— How it's made: <a href='https://huggingface.co/{initial_model}'><strong>{initial_model}</strong></a> was finetuned to create <a href='https://huggingface.co/{lora_model}'><strong>{lora_model}</strong></a>, then merged together to create <a href='https://huggingface.co/{merged_model}'><strong>{merged_model}</strong></a>.</p>
37
+ <p>πŸ“‰ Fine-tuning was performed using QLoRA techniques on the <a href='https://huggingface.co/datasets/{dataset}'><strong>{dataset}</strong></a> dataset. You can view training metrics on the <a href='https://huggingface.co/{lora_model}'><strong>QLoRa adapter HF Repo</strong></a>.</p>
38
+ <p>πŸ“Š All inputs/outputs are logged to Firebase to see how the model is doing.</a></p>
39
+ """)
40
+
41
+ examples = gr.Examples([
42
+ ["What is the average, minimum, and maximum age of all singers from France?", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
43
+ ["How many students have dogs?", "| student : stuid , lname , fname , age , sex , major , advisor , city_code | has_pet : stuid , petid | pets : petid , pettype , pet_age , weight | has_pet.stuid = student.stuid | has_pet.petid = pets.petid | pets.pettype = 'Dog' |"],
44
+ ], inputs=[input_text, db_info, temperature, top_p, top_k, repetition_penalty, format_sql, stop_sequence], fn=generate, cache_examples=False if platform.system() == "Windows" or platform.system() == "Darwin" else True, outputs=output_box)
45
+
46
+ with gr.Accordion("More Examples", open=False):
47
  examples = gr.Examples([
48
+ ["What is the average weight of pets of all students?", "| student : stuid , lname , fname , age , sex , major , advisor , city_code | has_pet : stuid , petid | pets : petid , pettype , pet_age , weight | has_pet.stuid = student.stuid | has_pet.petid = pets.petid |"],
49
+ ["How many male singers performed in concerts in the year 2023?", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
50
+ ["For students who have pets, how many pets does each student have? List their ids instead of names.", "| student : stuid , lname , fname , age , sex , major , advisor , city_code | has_pet : stuid , petid | pets : petid , pettype , pet_age , weight | has_pet.stuid = student.stuid | has_pet.petid = pets.petid |"],
51
  ["Show location and name for all stadiums with a capacity between 5000 and 10000.", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
52
  ["What are the number of concerts that occurred in the stadium with the largest capacity ?", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
53
+ ["Which student has the oldest pet?", "| student : stuid , lname , fname , age , sex , major , advisor , city_code | has_pet : stuid , petid | pets : petid , pettype , pet_age , weight | has_pet.stuid = student.stuid | has_pet.petid = pets.petid |"],
54
+ ["List the names of all singers who performed in a concert with the theme 'Rock'", "| stadium : stadium_id , location , name , capacity , highest , lowest , average | singer : singer_id , name , country , song_name , song_release_year , age , is_male | concert : concert_id , concert_name , theme , stadium_id , year | singer_in_concert : concert_id , singer_id | concert.stadium_id = stadium.stadium_id | singer_in_concert.singer_id = singer.singer_id | singer_in_concert.concert_id = concert.concert_id |"],
55
+ ["List all students who don't have pets.", "| student : stuid , lname , fname , age , sex , major , advisor , city_code | has_pet : stuid , petid | pets : petid , pettype , pet_age , weight | has_pet.stuid = student.stuid | has_pet.petid = pets.petid |"],
56
+ ], inputs=[input_text, db_info, temperature, top_p, top_k, repetition_penalty, format_sql, stop_sequence], fn=bot, cache_examples=False, outputs=output_box)
57
+
 
 
 
 
 
 
 
 
 
 
 
58
 
59
+ readme_content = requests.get(f"https://huggingface.co/{merged_model}/raw/main/README.md").text
60
+ readme_content = re.sub('---.*?---', '', readme_content, flags=re.DOTALL) #Remove YAML front matter
61
 
62
+ with gr.Accordion("πŸ“– Model Readme", open=True):
63
+ readme = gr.Markdown(
64
+ readme_content,
65
+ )
66
+
67
+ with gr.Accordion("More Options:", open=False):
68
+ log = gr.Checkbox(label="Log to Firebase", value=True, interactive=True)
69
+
70
+ # When the button is clicked, call the generate function, inputs are taken from the UI elements, outputs are sent to outputs elements
71
+ run_button.click(fn=bot, inputs=[input_text, db_info, temperature, top_p, top_k, repetition_penalty, format_sql, stop_sequence, log], outputs=output_box, api_name="txt2sql")
72
+
73
 
74
+ demo.queue(concurrency_count=1, max_size=20).launch(debug=True)