gradio / app.py
teaevo's picture
Update app.py
32680f1
raw
history blame
1 kB
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()