Spaces:
Runtime error
Runtime error
| 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() |