17Goutham commited on
Commit
9e7ebd4
1 Parent(s): 212ebbf

Upload 2 files

Browse files
Files changed (2) hide show
  1. app___init__.py +0 -0
  2. app_tapex.py +33 -0
app___init__.py ADDED
File without changes
app_tapex.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import TapasTokenizer, TapexTokenizer, BartForConditionalGeneration
2
+ import pandas as pd
3
+ import datetime
4
+ import torch
5
+
6
+
7
+ def execute_query(query, csv_file):
8
+ a = datetime.datetime.now()
9
+
10
+ table = pd.read_csv(csv_file.name, delimiter=",")
11
+ table = table.astype(str)
12
+
13
+ model_name = "microsoft/tapex-large-finetuned-wtq"
14
+ model = BartForConditionalGeneration.from_pretrained(model_name)
15
+ tokenizer = TapexTokenizer.from_pretrained(model_name)
16
+
17
+ queries = [query]
18
+
19
+ encoding = tokenizer(table=table, query=queries, padding=True, return_tensors="pt",truncation=True)
20
+ outputs = model.generate(**encoding)
21
+ ans = tokenizer.batch_decode(outputs, skip_special_tokens=True)
22
+
23
+
24
+
25
+ query_result = {
26
+ "query": query,
27
+ "answer": ans[0]
28
+ }
29
+
30
+ b = datetime.datetime.now()
31
+ print(b - a)
32
+
33
+ return query_result, table