Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import TapexTokenizer, BartForConditionalGeneration
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-large-finetuned-wtq")
|
6 |
+
model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-large-finetuned-wtq")
|
7 |
+
|
8 |
+
data = {
|
9 |
+
"year": [1896, 1900, 1904, 2004, 2008, 2012],
|
10 |
+
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
|
11 |
+
}
|
12 |
+
table = pd.DataFrame.from_dict(data)
|
13 |
+
|
14 |
+
# tapex accepts uncased input since it is pre-trained on the uncased corpus
|
15 |
+
query = "In which year did beijing host the Olympic Games?"
|
16 |
+
encoding = tokenizer(table=table, query=query, return_tensors="pt")
|
17 |
+
|
18 |
+
outputs = model.generate(**encoding)
|
19 |
+
|
20 |
+
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
|
21 |
+
# [' 2008.0']
|