Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
from datasets import load_dataset
|
4 |
|
5 |
# Load tokenizer and model
|
6 |
-
tokenizer =
|
7 |
-
model =
|
8 |
|
9 |
# Initialize the pipeline
|
10 |
nl2sql_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
@@ -13,11 +13,7 @@ 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 |
-
|
17 |
-
input_text = f"translate English to SQL: {query}"
|
18 |
-
# Run the pipeline
|
19 |
-
results = nl2sql_pipeline(input_text, max_length=512, num_return_sequences=1)
|
20 |
-
# Extract the SQL query
|
21 |
sql_query = results[0]['generated_text']
|
22 |
return sql_query
|
23 |
|
@@ -30,10 +26,10 @@ interface = gr.Interface(
|
|
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
|
34 |
description="This model converts natural language queries into SQL using the Spider dataset. 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 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 |
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 |
|
|
|
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()
|