Spaces:
Runtime error
Runtime error
Commit
•
6d99346
0
Parent(s):
Duplicate from juliensimon/table_questions
Browse filesCo-authored-by: Julien Simon <juliensimon@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +72 -0
- default_file.csv +21 -0
- 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
|
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: juliensimon/table_questions
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from transformers import (
|
4 |
+
AutoModelForSeq2SeqLM,
|
5 |
+
AutoModelForTableQuestionAnswering,
|
6 |
+
AutoTokenizer,
|
7 |
+
pipeline,
|
8 |
+
)
|
9 |
+
|
10 |
+
model_tapex = "microsoft/tapex-large-finetuned-wtq"
|
11 |
+
tokenizer_tapex = AutoTokenizer.from_pretrained(model_tapex)
|
12 |
+
model_tapex = AutoModelForSeq2SeqLM.from_pretrained(model_tapex)
|
13 |
+
pipe_tapex = pipeline(
|
14 |
+
"table-question-answering", model=model_tapex, tokenizer=tokenizer_tapex
|
15 |
+
)
|
16 |
+
|
17 |
+
model_tapas = "google/tapas-large-finetuned-wtq"
|
18 |
+
tokenizer_tapas = AutoTokenizer.from_pretrained(model_tapas)
|
19 |
+
model_tapas = AutoModelForTableQuestionAnswering.from_pretrained(model_tapas)
|
20 |
+
pipe_tapas = pipeline(
|
21 |
+
"table-question-answering", model=model_tapas, tokenizer=tokenizer_tapas
|
22 |
+
)
|
23 |
+
|
24 |
+
|
25 |
+
def process(query, file, correct_answer, rows=20):
|
26 |
+
table = pd.read_csv(file.name, header=0).astype(str)
|
27 |
+
table = table[:rows]
|
28 |
+
result_tapex = pipe_tapex(table=table, query=query)
|
29 |
+
result_tapas = pipe_tapas(table=table, query=query)
|
30 |
+
return result_tapex["answer"], result_tapas["answer"], correct_answer
|
31 |
+
|
32 |
+
|
33 |
+
# Inputs
|
34 |
+
query_text = gr.Text(label="Enter a question")
|
35 |
+
input_file = gr.File(label="Upload a CSV file", type="file")
|
36 |
+
rows_slider = gr.Slider(label="Number of rows")
|
37 |
+
|
38 |
+
# Output
|
39 |
+
answer_text_tapex = gr.Text(label="TAPEX answer")
|
40 |
+
answer_text_tapas = gr.Text(label="TAPAS answer")
|
41 |
+
|
42 |
+
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). \
|
43 |
+
Both have been fine-tuned on the [WikiTableQuestions](https://huggingface.co/datasets/wikitablequestions) dataset. \n\n\
|
44 |
+
A sample file with football statistics is available in the repository: \n\n\
|
45 |
+
* Which team has the most wins? Answer: Manchester City FC\n\
|
46 |
+
* Which team has the most wins: Chelsea, Liverpool or Everton? Answer: Liverpool\n\
|
47 |
+
* Which teams have scored less than 40 goals? Answer: Cardiff City FC, Fulham FC, Brighton & Hove Albion FC, Huddersfield Town FC\n\
|
48 |
+
* What is the average number of wins? Answer: 16 (rounded)\n\n\
|
49 |
+
You can also upload your own CSV file. Please note that maximum sequence length for both models is 1024 tokens, \
|
50 |
+
so you may need to limit the number of rows in your CSV file. Chunking is not implemented yet."
|
51 |
+
|
52 |
+
iface = gr.Interface(
|
53 |
+
theme="huggingface",
|
54 |
+
description=description,
|
55 |
+
layout="vertical",
|
56 |
+
fn=process,
|
57 |
+
inputs=[query_text, input_file, rows_slider],
|
58 |
+
outputs=[answer_text_tapex, answer_text_tapas],
|
59 |
+
examples=[
|
60 |
+
["Which team has the most wins?", "default_file.csv", 20],
|
61 |
+
[
|
62 |
+
"Which team has the most wins: Chelsea, Liverpool or Everton?",
|
63 |
+
"default_file.csv",
|
64 |
+
20,
|
65 |
+
],
|
66 |
+
["Which teams have scored less than 40 goals?", "default_file.csv", 20],
|
67 |
+
["What is the average number of wins?", "default_file.csv", 20],
|
68 |
+
],
|
69 |
+
allow_flagging="never",
|
70 |
+
)
|
71 |
+
|
72 |
+
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
|