Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
2 |
|
3 |
# Load the tokenizer and model
|
4 |
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-base-multi-summarization-sql-en")
|
5 |
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-base-multi-summarization-sql-en")
|
6 |
|
7 |
-
def
|
8 |
# Tokenize the input query
|
9 |
input_ids = tokenizer(natural_language_query, return_tensors="pt").input_ids
|
10 |
|
@@ -15,7 +16,22 @@ def nl_to_sql(natural_language_query):
|
|
15 |
sql_query = tokenizer.decode(output_ids, skip_special_tokens=True)
|
16 |
return sql_query
|
17 |
|
18 |
-
# Example
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
# Load the tokenizer and model
|
5 |
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-base-multi-summarization-sql-en")
|
6 |
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-base-multi-summarization-sql-en")
|
7 |
|
8 |
+
def generate_sql(natural_language_query):
|
9 |
# Tokenize the input query
|
10 |
input_ids = tokenizer(natural_language_query, return_tensors="pt").input_ids
|
11 |
|
|
|
16 |
sql_query = tokenizer.decode(output_ids, skip_special_tokens=True)
|
17 |
return sql_query
|
18 |
|
19 |
+
# Example questions for the interface
|
20 |
+
example_questions = [
|
21 |
+
"What is the average salary of employees?",
|
22 |
+
"List the names of employees who work in the IT department.",
|
23 |
+
"Count the number of employees who joined after 2015."
|
24 |
+
]
|
25 |
+
|
26 |
+
# Create the Gradio interface
|
27 |
+
interface = gr.Interface(
|
28 |
+
fn=generate_sql,
|
29 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
|
30 |
+
outputs="text",
|
31 |
+
examples=example_questions,
|
32 |
+
title="NL to SQL with CodeT5",
|
33 |
+
description="This model converts natural language queries into SQL using the WikiSQL dataset. Try one of the example questions or enter your own!"
|
34 |
+
)
|
35 |
+
|
36 |
+
# Launch the interface
|
37 |
+
interface.launch()
|