|
import gradio as gr |
|
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer |
|
|
|
def execute_sql(user_query): |
|
model_name = "microsoft/tapex-large-sql-execution" |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) |
|
|
|
inputs = tokenizer(user_query, return_tensors="pt", padding=True) |
|
outputs = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'], max_length=1024) |
|
response = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
return response |
|
|
|
|
|
iface = gr.Interface( |
|
fn=execute_sql, |
|
inputs=gr.Textbox(prompt="Enter your SQL query:"), |
|
outputs=gr.Textbox(), |
|
live=True, |
|
capture_session=True, |
|
title="SQL Execution Chatbot", |
|
description="Type your SQL query in the box above, and the chatbot will execute it.", |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |