File size: 1,003 Bytes
ec9ef8b
2ee70bc
f24bed6
32680f1
 
 
 
f24bed6
32680f1
 
2ee70bc
 
 
f24bed6
32680f1
 
1f73097
32680f1
23432db
 
 
32680f1
 
23432db
 
32680f1
23432db
32680f1
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
import gradio as gr
from transformers import AutoModelForQuestionAnswering, AutoTokenizer

# Load the Tapas model and tokenizer
model_name = "google/tapas-large-finetuned-wtq"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForQuestionAnswering.from_pretrained(model_name)

def execute_sql(user_query):
    inputs = tokenizer(user_query, return_tensors="pt")
    outputs = model(**inputs)
    answer = tokenizer.decode(inputs['input_ids'][0][outputs['start_logits'].argmax():outputs['end_logits'].argmax() + 1])
    return answer

# Define the chatbot interface using Gradio
iface = gr.Interface(
    fn=execute_sql,
    inputs=gr.Textbox(prompt="Enter your question:"),
    outputs=gr.Textbox(),
    live=True,
    capture_session=True,
    title="Database Question Answering Chatbot",
    description="Type your questions about the database in the box above, and the chatbot will provide answers.",
)

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