NLSQL / app.py
HusnaManakkot's picture
Update app.py
50aa5cd verified
raw
history blame
1.03 kB
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
model = AutoModelForSeq2SeqLM.from_pretrained("hrshtsharma2012/NL2SQL-Picard-final")
def generate_sql(query):
input_text = "SQL: " + query
inputs = tokenizer(input_text, return_tensors="pt", padding=True)
outputs = model.generate(**inputs, max_length=512)
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Remove the "SQL: " prefix from the output
sql_query = sql_query.replace("SQL: ", "")
return sql_query
# Create a Gradio interface
interface = gr.Interface(
fn=generate_sql,
inputs=gr.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. Enter your query!"
)
# Launch the app
if __name__ == "__main__":
interface.launch()