File size: 3,063 Bytes
76b8afe
 
 
 
 
 
 
 
 
 
64041f8
76b8afe
 
 
 
 
 
64041f8
76b8afe
 
 
5eb07df
76b8afe
5329b0e
76b8afe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64041f8
76b8afe
 
 
 
 
 
 
d835172
1
2
3
4
5
6
7
8
9
10
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
from transformers import BloomTokenizerFast, BloomForCausalLM, pipeline
import torch
import gradio as gr

def sql_generate(prompt,input_prompt_sql):
  checkpoint="bigscience/bloom-1b3"
  tokenizer= BloomTokenizerFast.from_pretrained(checkpoint)
  model=BloomForCausalLM.from_pretrained(checkpoint)
  
  text_generator = pipeline(
          "text-generation", model=model, tokenizer=tokenizer
      )
  
  if len(prompt) == 0:
    prompt = input_prompt_sql 
  
  model_args= {
          "max_length":40,
          "top_p": 0.9,
          "temperature": 1.1,
          "return_full_text": False,
          "use_cache": False,
          "wait_for_model": True,
          "random_seed":42
      }
  generated_text = text_generator(prompt, **model_args)[0]["generated_text"]
  return generated_text
  
  
demo = gr.Blocks()

with demo:
  gr.Markdown("<h1><center>Zero Shot SQL by Bloom</center></h1>")
        
  with gr.Row():
  
    example_prompt = gr.Radio( [
    "Instruction: Given an input question, respond with syntactically correct PostgreSQL\nInput: How many users signed up in the past month?\nPostgreSQL query: ", 
    "Instruction: Given an input question, respond with syntactically correct PostgreSQL\nInput: Create a query that displays empfname, emplname, deptid, deptname, location from employee table. Results should be in the ascending order based on the empfname and location.\nPostgreSQL query: ", 
    "Instruction: Given an input question, respond with syntactically correct PostgreSQL. Only use table called 'employees'.\nInput: What is the total salary paid to all the employees?\nPostgreSQL query: ",
    "Instruction: Given an input question, respond with syntactically correct PostgreSQL. Only use table called 'employees'.\nInput: List names of all the employees whose name end with 'r'.\nPostgreSQL query: ",
    "Instruction: Given an input question, respond with syntactically correct PostgreSQL. Only use table called 'employees'.\nInput: What are the number of employees in each department?\nPostgreSQL query: ",
    "Instruction: Given an input question, respond with syntactically correct PostgreSQL. Only use table called 'employees'.\nInput: Select names of all theemployees who have third character in their name as 't'.\nPostgreSQL query: ",
    "Instruction: Given an input question, respond with syntactically correct PostgreSQL. Only use table called 'employees'.\nInput: Select names of all the employees who are working under 'Peter'.\nPostgreSQL query: ",  ], label= "Choose a sample Prompt")
  
    #with gr.Column:  
    input_prompt_sql = gr.Textbox(label="Or Write text following the example pattern given below, to get SQL commands...", value="Instruction: Given an input question, respond with syntactically correct PostgreSQL\nInput: How many users signed up in the past month?\nPostgreSQL query: ", lines=6)
    
  with gr.Row():
    generated_txt = gr.Textbox(lines=3)

  b1 = gr.Button("Generate SQL")
  b1.click(sql_generate,inputs=[example_prompt, input_prompt_sql], outputs=generated_txt) 
  
demo.launch()