|
import gradio as gr |
|
from transformers import TapexTokenizer, BartForConditionalGeneration |
|
import pandas as pd |
|
import pkg_resources |
|
|
|
|
|
installed_packages = {pkg.key: pkg.version for pkg in pkg_resources.working_set} |
|
|
|
|
|
for package, version in installed_packages.items(): |
|
print(f"{package}=={version}") |
|
|
|
|
|
|
|
|
|
|
|
model_name = "microsoft/tapex-large-finetuned-wtq" |
|
|
|
|
|
tokenizer = TapexTokenizer.from_pretrained(model_name) |
|
model = BartForConditionalGeneration.from_pretrained(model_name) |
|
|
|
data = { |
|
"year": [1896, 1900, 1904, 2004, 2008, 2012], |
|
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"] |
|
} |
|
table = pd.DataFrame.from_dict(data) |
|
|
|
def chatbot_response(user_message): |
|
|
|
|
|
inputs = user_message |
|
encoding = tokenizer(table=table, query=inputs, return_tensors="pt") |
|
outputs = model.generate(**encoding) |
|
response = tokenizer.batch_decode(outputs, skip_special_tokens=True) |
|
|
|
return response |
|
|
|
|
|
iface = gr.Interface( |
|
fn=chatbot_response, |
|
inputs=gr.Textbox(prompt="You:"), |
|
outputs=gr.Textbox(), |
|
live=True, |
|
capture_session=True, |
|
title="ST SQL Chatbot", |
|
description="Type your message in the box above, and the chatbot will respond.", |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|