HusnaManakkot commited on
Commit
84b4e3d
Β·
verified Β·
1 Parent(s): eefed22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -28
app.py CHANGED
@@ -1,39 +1,23 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
- from datasets import load_dataset
4
 
5
- # Load tokenizer and model
6
- tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-wikiSQL")
7
- model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/t5-base-finetuned-wikiSQL")
8
 
9
- # Initialize the pipeline
10
- nl2sql_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
11
-
12
- # Load a part of the Spider dataset
13
- spider_dataset = load_dataset("spider", split='train[:5]')
14
-
15
- def generate_sql(query):
16
- # Format the input for the model
17
- input_text = f"translate English to SQL: {query}"
18
- # Run the pipeline
19
- results = nl2sql_pipeline(input_text)
20
- # Extract the SQL query
21
- sql_query = results[0]['generated_text']
22
  return sql_query
23
 
24
- # Use examples from the Spider dataset
25
- example_questions = [(question['question'],) for question in spider_dataset]
26
-
27
- # Create a Gradio interface
28
  interface = gr.Interface(
29
  fn=generate_sql,
30
- inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
31
- outputs="text",
32
- examples=example_questions,
33
- title="NL to SQL with T5",
34
- description="This model converts natural language queries into SQL. Try one of the example questions or enter your own!"
35
  )
36
 
37
- # Launch the app
38
  if __name__ == "__main__":
39
  interface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
3
 
4
+ # Load the NL2SQL model
5
+ model_id = "hrshtsharma2012/NL2SQL-Picard-final"
6
+ nl2sql = pipeline("text2text-generation", model=model_id)
7
 
8
+ def generate_sql(nl_query):
9
+ # Generate the SQL query from the natural language input
10
+ sql_query = nl2sql(nl_query)[0]["generated_text"]
 
 
 
 
 
 
 
 
 
 
11
  return sql_query
12
 
13
+ # Create the Gradio interface
 
 
 
14
  interface = gr.Interface(
15
  fn=generate_sql,
16
+ inputs=gr.Textbox(label="Natural Language Query"),
17
+ outputs=gr.Textbox(label="SQL Query"),
18
+ title="NL to SQL Converter",
19
+ description="Enter a natural language query and get the corresponding SQL query.",
 
20
  )
21
 
 
22
  if __name__ == "__main__":
23
  interface.launch()