Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
from datasets import load_dataset
|
4 |
-
import random
|
5 |
|
6 |
# Load the Spider dataset
|
7 |
-
spider_dataset = load_dataset("spider", split='train')
|
8 |
|
9 |
# Load tokenizer and model
|
10 |
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-wikiSQL")
|
@@ -17,27 +16,15 @@ def generate_sql(query):
|
|
17 |
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
return sql_query
|
19 |
|
20 |
-
def get_random_example():
|
21 |
-
example = random.choice(spider_dataset)
|
22 |
-
return example['question'], generate_sql(example['question'])
|
23 |
-
|
24 |
# Create a Gradio interface
|
25 |
interface = gr.Interface(
|
26 |
fn=generate_sql,
|
27 |
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
|
28 |
outputs="text",
|
29 |
title="NL to SQL with T5",
|
30 |
-
description="This model converts natural language queries into SQL. Enter your query
|
31 |
-
)
|
32 |
-
|
33 |
-
# Add a button to get a random example from the dataset
|
34 |
-
interface.add_component(
|
35 |
-
gr.Button("Get Random Example"),
|
36 |
-
fn=get_random_example,
|
37 |
-
inputs=[],
|
38 |
-
outputs=[gr.Textbox(label="Random Question"), gr.Textbox(label="Generated SQL")]
|
39 |
)
|
40 |
|
41 |
# Launch the app
|
42 |
if __name__ == "__main__":
|
43 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
from datasets import load_dataset
|
|
|
4 |
|
5 |
# Load the Spider dataset
|
6 |
+
spider_dataset = load_dataset("spider", split='train[:5]')
|
7 |
|
8 |
# Load tokenizer and model
|
9 |
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-wikiSQL")
|
|
|
16 |
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
17 |
return sql_query
|
18 |
|
|
|
|
|
|
|
|
|
19 |
# Create a Gradio interface
|
20 |
interface = gr.Interface(
|
21 |
fn=generate_sql,
|
22 |
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language query here..."),
|
23 |
outputs="text",
|
24 |
title="NL to SQL with T5",
|
25 |
+
description="This model converts natural language queries into SQL. Enter your query!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
)
|
27 |
|
28 |
# Launch the app
|
29 |
if __name__ == "__main__":
|
30 |
+
interface.launch()
|