Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,9 @@
|
|
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("
|
7 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("
|
8 |
-
|
9 |
-
# Load a part of the Spider dataset
|
10 |
-
spider_dataset = load_dataset("spider", split='train[:5]')
|
11 |
|
12 |
def generate_sql(query):
|
13 |
inputs = tokenizer(query, return_tensors="pt", padding=True)
|
@@ -15,17 +11,13 @@ def generate_sql(query):
|
|
15 |
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
return sql_query
|
17 |
|
18 |
-
# Use examples from the Spider dataset
|
19 |
-
example_questions = [(question['question'],) for question in spider_dataset]
|
20 |
-
|
21 |
# Create a Gradio interface
|
22 |
interface = gr.Interface(
|
23 |
fn=generate_sql,
|
24 |
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
|
25 |
outputs="text",
|
26 |
-
|
27 |
-
|
28 |
-
description="This model converts natural language queries into SQL. Try one of the example questions or enter your own!"
|
29 |
)
|
30 |
|
31 |
# 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("Salesforce/codet5-base-sql-en")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-base-sql-en")
|
|
|
|
|
|
|
7 |
|
8 |
def generate_sql(query):
|
9 |
inputs = tokenizer(query, return_tensors="pt", padding=True)
|
|
|
11 |
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
12 |
return sql_query
|
13 |
|
|
|
|
|
|
|
14 |
# Create a Gradio interface
|
15 |
interface = gr.Interface(
|
16 |
fn=generate_sql,
|
17 |
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
|
18 |
outputs="text",
|
19 |
+
title="NL to SQL with CodeT5",
|
20 |
+
description="This model converts natural language queries into SQL using datasets. Enter your query and get the SQL translation!"
|
|
|
21 |
)
|
22 |
|
23 |
# Launch the app
|