File size: 1,081 Bytes
54e8483
4c23181
54e8483
4c23181
 
 
54e8483
4c23181
 
9b65c50
4c23181
 
 
 
 
b503163
3b69718
4c23181
 
b503163
4c23181
 
 
 
3b69718
 
 
 
4c23181
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline

# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
model = AutoModelForSeq2SeqLM.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")

# Initialize the pipeline
nl2sql_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)

def generate_sql(query):
    # Use the model to generate SQL from the natural language query
    results = nl2sql_pipeline(query)
    # Extract the first result (highest likelihood)
    sql_query = results[0]['generated_text']
    return sql_query

# Create a Gradio interface
interface = gr.Interface(
    fn=generate_sql,
    inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your natural language query here..."),
    outputs="text",
    title="NL to SQL with Picard",
    description="This model converts natural language queries into SQL. It's based on the Spider dataset. Enter a query to get started!"
)

# Launch the app
if __name__ == "__main__":
    interface.launch()