|
import gradio as gr |
|
from transformers import TapexTokenizer, BartForConditionalGeneration |
|
import pandas as pd |
|
|
|
tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-large-finetuned-wtq") |
|
model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-large-finetuned-wtq") |
|
|
|
data = { |
|
"year": [1896, 1900, 1904, 2004, 2008, 2012], |
|
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"] |
|
} |
|
table = pd.DataFrame.from_dict(data) |
|
|
|
|
|
query = "how many different countries had election in 21st century?" |
|
encoding = tokenizer(table=table, query=query, return_tensors="pt") |
|
|
|
outputs = model.generate(**encoding) |
|
|
|
print(tokenizer.batch_decode(outputs, skip_special_tokens=True)) |
|
|