Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,24 @@
|
|
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 |
-
|
|
|
14 |
outputs = model.generate(**inputs, max_length=512)
|
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 using the Spider dataset. 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("mrm8488/t5-base-finetuned-wikiSQL")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/t5-base-finetuned-wikiSQL")
|
|
|
|
|
|
|
7 |
|
8 |
def generate_sql(query):
|
9 |
+
input_text = "translate English to SQL: " + query
|
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 |
return sql_query
|
14 |
|
|
|
|
|
|
|
15 |
# Create a Gradio interface
|
16 |
interface = gr.Interface(
|
17 |
fn=generate_sql,
|
18 |
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
|
19 |
outputs="text",
|
20 |
+
title="NL to SQL with T5",
|
21 |
+
description="This model converts natural language queries into SQL. Enter your query!"
|
|
|
22 |
)
|
23 |
|
24 |
# Launch the app
|