HusnaManakkot commited on
Commit
c5e0aa6
Β·
verified Β·
1 Parent(s): 1a2cecb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -6,16 +6,13 @@ from datasets import load_dataset
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
- # Ensure that we get the first generated text as the SQL query
18
- sql_query = results[0]['generated_text'] if results else "No SQL query generated"
19
  return sql_query
20
 
21
  # Use examples from the Spider dataset
@@ -28,7 +25,7 @@ interface = gr.Interface(
28
  outputs="text",
29
  examples=example_questions,
30
  title="NL to SQL with Picard",
31
- description="This model converts natural language queries into SQL using the Spider dataset. Try one of the example questions or enter your own!"
32
  )
33
 
34
  # Launch the app
 
6
  tokenizer = AutoTokenizer.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
7
  model = AutoModelForSeq2SeqLM.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
8
 
 
 
 
9
  # Load a part of the Spider dataset
10
  spider_dataset = load_dataset("spider", split='train[:5]')
11
 
12
  def generate_sql(query):
13
+ input_ids = tokenizer(query, return_tensors="pt").input_ids
14
+ outputs = model.generate(input_ids)
15
+ sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
  return sql_query
17
 
18
  # Use examples from the Spider dataset
 
25
  outputs="text",
26
  examples=example_questions,
27
  title="NL to SQL with Picard",
28
+ description="This model converts natural language queries into SQL using the Spider dataset. Try example questions or enter your own!"
29
  )
30
 
31
  # Launch the app