|
import gradio as gr |
|
from transformers import AutoModelForQuestionAnswering, AutoTokenizer |
|
|
|
|
|
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 |
|
|
|
|
|
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.", |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|