Spaces:
Runtime error
Runtime error
File size: 926 Bytes
54e8483 9a6e449 54e8483 bd0d5ac e291093 bd0d5ac aff9b4b 9a6e449 c5e0aa6 b503163 3b69718 bd0d5ac 4c23181 b503163 bd0d5ac e291093 3b69718 bd0d5ac 2a369c5 1a2cecb |
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 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-base-sql-en")
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-base-sql-en")
def generate_sql(query):
inputs = tokenizer(query, return_tensors="pt", padding=True)
outputs = model.generate(**inputs, max_length=512)
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
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 CodeT5",
description="This model converts natural language queries into SQL using datasets. Enter your query and get the SQL translation!"
)
# Launch the app
if __name__ == "__main__":
interface.launch()
|