File size: 1,004 Bytes
ec9ef8b
1f73097
f24bed6
1f73097
 
f24bed6
1f73097
f24bed6
1f73097
 
f24bed6
 
 
 
23432db
 
1f73097
 
23432db
 
 
1f73097
 
23432db
 
 
 
1f73097
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
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

def execute_sql(user_query):
    model_name = "microsoft/tapex-large-sql-execution"  # Tapex large SQL execution model
    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

# Define the chatbot interface using Gradio
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.",
)

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