Spaces:
Runtime error
Runtime error
Commit
·
bd87473
1
Parent(s):
7ac4ede
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from transformers import AutoModelForSeq2SeqLM, AutoModelForTableQuestionAnswering, AutoTokenizer, pipeline
|
4 |
+
|
5 |
+
model_tapas = "google/tapas-large-finetuned-wtq"
|
6 |
+
|
7 |
+
tokenizer_tapas = AutoTokenizer.from_pretrained(model_tapas)
|
8 |
+
pipe_tapas = pipeline("table-question-answering", model=model_tapas, tokenizer=tokenizer_tapas)
|
9 |
+
|
10 |
+
def process(query, file, correct_answer):
|
11 |
+
table = pd.read_csv(file.name).astype(str).fillna('')
|
12 |
+
#table = table[:rows] if rows else table
|
13 |
+
result_tapas = pipe_tapas(table = table, query = query)
|
14 |
+
return result_tapas['answer'], correct_answer
|
15 |
+
|
16 |
+
|
17 |
+
query_text = gr.Text(label = "Enter a question")
|
18 |
+
input_file = gr.File(label = "Upload a CVS file", type = "file")
|
19 |
+
|
20 |
+
# outputs from the app
|
21 |
+
answer_text_tapas = gr.Text(label = "TAPAS answer")
|
22 |
+
|
23 |
+
description = """
|
24 |
+
# Siddharth Test Gradio Table QA
|
25 |
+
"""
|
26 |
+
|
27 |
+
iface = gr.Interface(
|
28 |
+
theme="huggingface",
|
29 |
+
description=description,
|
30 |
+
fn = process,
|
31 |
+
inputs = [query_text, input_file,],
|
32 |
+
outputs = [answer_text_tapas],
|
33 |
+
examples = [["Apps with more than 4.7 rating in art and design?","playstore_text_csv.csv","Harley Quinn wallpapers HD --- ",],
|
34 |
+
["How many apps have Beauty genres?","playstore_text_csv.csv",""],
|
35 |
+
["Average Installs of apps with Beauty genres?","playstore_text_csv.csv",""] ]
|
36 |
+
,
|
37 |
+
allow_flagging="never"
|
38 |
+
)
|
39 |
+
|
40 |
+
|
41 |
+
iface.launch(share=True)
|