Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
|
|
3 |
|
4 |
# Load tokenizer and model
|
5 |
tokenizer = AutoTokenizer.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
|
@@ -8,21 +9,16 @@ model = AutoModelForSeq2SeqLM.from_pretrained("hrshtsharma2012/NL2SQL-Picard-fin
|
|
8 |
# Initialize the pipeline
|
9 |
nl2sql_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
10 |
|
|
|
|
|
|
|
11 |
def generate_sql(query):
|
12 |
-
# Use the model to generate SQL from the natural language query
|
13 |
results = nl2sql_pipeline(query)
|
14 |
-
# Extract the first result (highest likelihood)
|
15 |
sql_query = results[0]['generated_text']
|
16 |
return sql_query
|
17 |
|
18 |
-
#
|
19 |
-
example_questions = [
|
20 |
-
("How many heads of the departments are older than 56 ?",),
|
21 |
-
("List the name, born state and age of the heads of departments ordered by age.",),
|
22 |
-
("List the creation year, name and budget of each department.",),
|
23 |
-
("What are the maximum and minimum budget of the departments?",),
|
24 |
-
("In which year were most departments established?.",)
|
25 |
-
]
|
26 |
|
27 |
# Create a Gradio interface
|
28 |
interface = gr.Interface(
|
@@ -31,7 +27,7 @@ interface = gr.Interface(
|
|
31 |
outputs="text",
|
32 |
examples=example_questions,
|
33 |
title="NL to SQL with Picard",
|
34 |
-
description="This model converts natural language queries into SQL
|
35 |
)
|
36 |
|
37 |
# Launch the app
|
|
|
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")
|
|
|
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(
|
|
|
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
|