File size: 1,124 Bytes
608b8bc a9d7f91 608b8bc a9d7f91 608b8bc a9d7f91 7ca2216 a9d7f91 |
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 30 31 32 |
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)
# tapex accepts uncased input since it is pre-trained on the uncased corpus
#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))
# [' 2008.0']
def launch(input):
encoding = tokenizer(table=table, query=input, return_tensors="pt")
outputs=model.generate(**encoding)
return tokenizer.batch_decode(outputs, skip_special_tokens=True)
iface = gr.Interface(launch,
inputs="text",
outputs="text")
iface.launch(share=True)
|