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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -3,8 +3,8 @@ 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)
@@ -13,12 +13,14 @@ nl2sql_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokeni
13
  spider_dataset = load_dataset("spider", split='train[:5]')
14
 
15
  def generate_sql(query):
16
- formatted_query = f"translate English to SQL: {query}"
17
- results = nl2sql_pipeline(formatted_query)
 
 
 
18
  sql_query = results[0]['generated_text']
19
  return sql_query
20
 
21
-
22
  # Use examples from the Spider dataset
23
  example_questions = [(question['question'],) for question in spider_dataset]
24
 
@@ -28,10 +30,10 @@ interface = gr.Interface(
28
  inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
29
  outputs="text",
30
  examples=example_questions,
31
- title="NL to SQL with Picard",
32
- description="This model converts natural language queries into SQL using the Spider dataset. Try one of the example questions or enter your own!"
33
  )
34
 
35
  # Launch the app
36
  if __name__ == "__main__":
37
- interface.launch()
 
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)
 
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
 
 
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()