Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
-
from datasets import load_dataset
|
4 |
|
5 |
# Load tokenizer and model
|
6 |
tokenizer = AutoTokenizer.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
|
@@ -11,6 +10,11 @@ def generate_sql(query):
|
|
11 |
inputs = tokenizer(input_text, return_tensors="pt", padding=True)
|
12 |
outputs = model.generate(**inputs, max_length=512)
|
13 |
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
14 |
return sql_query
|
15 |
|
16 |
# Create a Gradio interface
|
@@ -19,7 +23,7 @@ interface = gr.Interface(
|
|
19 |
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
|
20 |
outputs="text",
|
21 |
title="NL to SQL with Picard",
|
22 |
-
description="This model converts natural language queries into SQL
|
23 |
)
|
24 |
|
25 |
# Launch the app
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
3 |
|
4 |
# Load tokenizer and model
|
5 |
tokenizer = AutoTokenizer.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
|
|
|
10 |
inputs = tokenizer(input_text, return_tensors="pt", padding=True)
|
11 |
outputs = model.generate(**inputs, max_length=512)
|
12 |
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
+
|
14 |
+
# Check if the output is the same as the input
|
15 |
+
if sql_query.strip().lower() == query.strip().lower():
|
16 |
+
return "The model did not generate a SQL query. Please try a different input or use a different model."
|
17 |
+
|
18 |
return sql_query
|
19 |
|
20 |
# Create a Gradio interface
|
|
|
23 |
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
|
24 |
outputs="text",
|
25 |
title="NL to SQL with Picard",
|
26 |
+
description="This model converts natural language queries into SQL. Enter your query!"
|
27 |
)
|
28 |
|
29 |
# Launch the app
|