king007 commited on
Commit
40d15de
1 Parent(s): 4931940

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -1,12 +1,13 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
- import pandas as pd
4
  from transformers import (
5
  AutoModelForSeq2SeqLM,
6
  AutoModelForTableQuestionAnswering,
7
  AutoTokenizer,
8
  pipeline,
 
 
9
  )
 
10
 
11
  # model_tapex = "microsoft/tapex-large-finetuned-wtq"
12
  # tokenizer_tapex = AutoTokenizer.from_pretrained(model_tapex)
@@ -16,7 +17,8 @@ from transformers import (
16
  # )
17
 
18
  #new
19
- pipe_tapex = pipeline(task="table-question-answering", model="microsoft/tapex-large-finetuned-wtq")
 
20
 
21
 
22
  # model_tapas = "google/tapas-large-finetuned-wtq"
@@ -30,16 +32,16 @@ pipe_tapex = pipeline(task="table-question-answering", model="microsoft/tapex-la
30
  pipe_tapas = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq")
31
 
32
 
33
- def process(query, file, correct_answer, rows=20):
34
- table = pd.read_csv(file.name, header=0).astype(str)
35
- table = table[:rows]
36
- result_tapex = pipe_tapex(table=table, query=query)
37
- return result_tapex["answer"], result_tapas["answer"], correct_answer
38
 
39
  def process2(query, csv_data):
40
  csv_data={"Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], "Number of movies": ["87", "53", "69"]}
41
  table = pd.DataFrame.from_dict(csv_data)
42
- result_tapex = pipe_tapex(table=table, query=query)['cells'][0]
 
 
 
 
43
  result_tapas = pipe_tapas(table=table, query=query)['cells'][0]
44
  return result_tapex, result_tapas
45
 
 
1
  import gradio as gr
 
 
2
  from transformers import (
3
  AutoModelForSeq2SeqLM,
4
  AutoModelForTableQuestionAnswering,
5
  AutoTokenizer,
6
  pipeline,
7
+ TapexTokenizer,
8
+ BartForConditionalGeneration
9
  )
10
+ import pandas as pd
11
 
12
  # model_tapex = "microsoft/tapex-large-finetuned-wtq"
13
  # tokenizer_tapex = AutoTokenizer.from_pretrained(model_tapex)
 
17
  # )
18
 
19
  #new
20
+ tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-base")
21
+ model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-base")
22
 
23
 
24
  # model_tapas = "google/tapas-large-finetuned-wtq"
 
32
  pipe_tapas = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq")
33
 
34
 
35
+
 
 
 
 
36
 
37
  def process2(query, csv_data):
38
  csv_data={"Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], "Number of movies": ["87", "53", "69"]}
39
  table = pd.DataFrame.from_dict(csv_data)
40
+ #microsoft
41
+ encoding = tokenizer(table=table, query=query, return_tensors="pt")
42
+ outputs = model.generate(**encoding)
43
+ result_tapex=tokenizer.batch_decode(outputs, skip_special_tokens=True)
44
+ #google
45
  result_tapas = pipe_tapas(table=table, query=query)['cells'][0]
46
  return result_tapex, result_tapas
47