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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -1,23 +1,35 @@
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()
 
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("hrshtsharma2012/NL2SQL-Picard-final")
7
+ model = AutoModelForSeq2SeqLM.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
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
+ results = nl2sql_pipeline(query)
17
+ sql_query = results[0]['generated_text']
18
  return sql_query
19
 
20
+ # Use examples from the Spider dataset
21
+ example_questions = [(question['question'],) for question in spider_dataset]
22
+
23
+ # Create a Gradio interface
24
  interface = gr.Interface(
25
  fn=generate_sql,
26
+ inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
27
+ outputs="text",
28
+ examples=example_questions,
29
+ title="NL to SQL with Picard",
30
+ description="This model converts natural language queries into SQL using the Spider dataset. Try one of the example questions or enter your own!"
31
  )
32
 
33
+ # Launch the app
34
  if __name__ == "__main__":
35
+ interface.launch()