Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
from datasets import load_dataset
|
4 |
|
5 |
-
# Load
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
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 |
-
# 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 |
-
#
|
25 |
-
example_questions = [(question['question'],) for question in spider_dataset]
|
26 |
-
|
27 |
-
# Create a Gradio interface
|
28 |
interface = gr.Interface(
|
29 |
fn=generate_sql,
|
30 |
-
inputs=gr.Textbox(
|
31 |
-
outputs="
|
32 |
-
|
33 |
-
|
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()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Load the NL2SQL model
|
5 |
+
model_id = "hrshtsharma2012/NL2SQL-Picard-final"
|
6 |
+
nl2sql = pipeline("text2text-generation", model=model_id)
|
7 |
|
8 |
+
def generate_sql(nl_query):
|
9 |
+
# Generate the SQL query from the natural language input
|
10 |
+
sql_query = nl2sql(nl_query)[0]["generated_text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
return sql_query
|
12 |
|
13 |
+
# Create the Gradio interface
|
|
|
|
|
|
|
14 |
interface = gr.Interface(
|
15 |
fn=generate_sql,
|
16 |
+
inputs=gr.Textbox(label="Natural Language Query"),
|
17 |
+
outputs=gr.Textbox(label="SQL Query"),
|
18 |
+
title="NL to SQL Converter",
|
19 |
+
description="Enter a natural language query and get the corresponding SQL query.",
|
|
|
20 |
)
|
21 |
|
|
|
22 |
if __name__ == "__main__":
|
23 |
interface.launch()
|