king007 commited on
Commit
c0d5863
β€’
0 Parent(s):

Duplicate from king007/table_questions2

Browse files
Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +88 -0
  4. default_file.csv +21 -0
  5. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Table Questions 2
3
+ emoji: 🐠
4
+ colorFrom: red
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.16.2
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: king007/table_questions2
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import json
12
+
13
+ # model_tapex = "microsoft/tapex-large-finetuned-wtq"
14
+ # tokenizer_tapex = AutoTokenizer.from_pretrained(model_tapex)
15
+ # model_tapex = AutoModelForSeq2SeqLM.from_pretrained(model_tapex)
16
+ # pipe_tapex = pipeline(
17
+ # "table-question-answering", model=model_tapex, tokenizer=tokenizer_tapex
18
+ # )
19
+
20
+ #new
21
+ tokenizer = TapexTokenizer.from_pretrained("microsoft/tapex-large-finetuned-wtq")
22
+ model = BartForConditionalGeneration.from_pretrained("microsoft/tapex-large-finetuned-wtq")
23
+
24
+
25
+ # model_tapas = "google/tapas-large-finetuned-wtq"
26
+ # tokenizer_tapas = AutoTokenizer.from_pretrained(model_tapas)
27
+ # model_tapas = AutoModelForTableQuestionAnswering.from_pretrained(model_tapas)
28
+ # pipe_tapas = pipeline(
29
+ # "table-question-answering", model=model_tapas, tokenizer=tokenizer_tapas
30
+ # )
31
+
32
+ #new
33
+ pipe_tapas = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq")
34
+ pipe_tapas2 = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wikisql-supervised")
35
+
36
+
37
+
38
+
39
+ def process2(query, csv_dataStr):
40
+ # csv_data={"Actors": ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], "Number of movies": ["87", "53", "69"]}
41
+ csv_data = json.loads(csv_dataStr)
42
+ table = pd.DataFrame.from_dict(csv_data)
43
+ #microsoft
44
+ encoding = tokenizer(table=table, query=query, return_tensors="pt")
45
+ outputs = model.generate(**encoding)
46
+ result_tapex=tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
47
+ #google
48
+ result_tapas = pipe_tapas(table=table, query=query)['cells'][0]
49
+ #google2
50
+ result_tapas2 = pipe_tapas2(table=table, query=query)['cells'][0]
51
+ return result_tapex, result_tapas, result_tapas2
52
+
53
+
54
+ # Inputs
55
+ query_text = gr.Text(label="")
56
+ # input_file = gr.File(label="Upload a CSV file", type="file")
57
+ input_data = gr.Text(label="")
58
+ # rows_slider = gr.Slider(label="Number of rows")
59
+
60
+ # Output
61
+ answer_text_tapex = gr.Text(label="")
62
+ answer_text_tapas = gr.Text(label="")
63
+ answer_text_tapas2 = gr.Text(label="")
64
+
65
+ description = "This Space lets you ask questions on CSV documents with Microsoft [TAPEX-Large](https://huggingface.co/microsoft/tapex-large-finetuned-wtq) and Google [TAPAS-Large](https://huggingface.co/google/tapas-large-finetuned-wtq). \
66
+ Both have been fine-tuned on the [WikiTableQuestions](https://huggingface.co/datasets/wikitablequestions) dataset. \n\n\
67
+ A sample file with football statistics is available in the repository: \n\n\
68
+ * Which team has the most wins? Answer: Manchester City FC\n\
69
+ * Which team has the most wins: Chelsea, Liverpool or Everton? Answer: Liverpool\n\
70
+ * Which teams have scored less than 40 goals? Answer: Cardiff City FC, Fulham FC, Brighton & Hove Albion FC, Huddersfield Town FC\n\
71
+ * What is the average number of wins? Answer: 16 (rounded)\n\n\
72
+ You can also upload your own CSV file. Please note that maximum sequence length for both models is 1024 tokens, \
73
+ so you may need to limit the number of rows in your CSV file. Chunking is not implemented yet."
74
+
75
+ iface = gr.Interface(
76
+ theme="huggingface",
77
+ description=description,
78
+ layout="vertical",
79
+ fn=process2,
80
+ inputs=[query_text, input_data],
81
+ outputs=[answer_text_tapex, answer_text_tapas, answer_text_tapas2],
82
+ examples=[
83
+
84
+ ],
85
+ allow_flagging="never",
86
+ )
87
+
88
+ iface.launch()
default_file.csv ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ team_name,common_name,wins,draws,draws_home,draws_away,losses,points_per_game,league_position,goals_scored,goals_conceded,goal_difference,total_goal_count
2
+ Arsenal FC,Arsenal,21,7,3,4,10,1.84,5,73,51,22,124
3
+ Tottenham Hotspur FC,Tottenham Hotspur,23,2,2,0,13,1.87,4,67,39,28,106
4
+ Manchester City FC,Manchester City,32,2,0,2,4,2.58,1,95,23,72,118
5
+ Leicester City FC,Leicester City,15,7,3,4,16,1.37,9,51,48,3,99
6
+ Crystal Palace FC,Crystal Palace,14,7,5,2,17,1.29,12,51,53,-2,104
7
+ Everton FC,Everton,15,9,4,5,14,1.42,8,54,46,8,100
8
+ Burnley FC,Burnley,11,7,2,5,20,1.05,15,45,68,-23,113
9
+ Southampton FC,Southampton,9,12,8,4,17,1.03,16,45,65,-20,110
10
+ AFC Bournemouth,AFC Bournemouth,13,6,5,1,19,1.18,14,56,70,-14,126
11
+ Manchester United FC,Manchester United,19,9,6,3,10,1.74,6,65,54,11,119
12
+ Liverpool FC,Liverpool,30,7,2,5,1,2.55,2,89,22,67,111
13
+ Chelsea FC,Chelsea,21,9,6,3,8,1.89,3,63,39,24,102
14
+ West Ham United FC,West Ham United,15,7,4,3,16,1.37,10,52,55,-3,107
15
+ Watford FC,Watford,14,8,3,5,16,1.32,11,52,59,-7,111
16
+ Newcastle United FC,Newcastle United,12,9,1,8,17,1.18,13,42,48,-6,90
17
+ Cardiff City FC,Cardiff City,10,4,2,2,24,0.89,18,34,69,-35,103
18
+ Fulham FC,Fulham,7,5,3,2,26,0.68,19,34,81,-47,115
19
+ Brighton & Hove Albion FC,Brighton & Hove Albion,9,9,5,4,20,0.95,17,35,60,-25,95
20
+ Huddersfield Town FC,Huddersfield Town,3,7,3,4,28,0.42,20,22,76,-54,98
21
+ Wolverhampton Wanderers FC,Wolverhampton Wanderers,16,9,4,5,13,1.5,7,47,46,1,93
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch