File size: 1,368 Bytes
bd87473
 
 
 
 
 
 
 
 
 
 
 
 
935bae0
bd87473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb262b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr 
import pandas as pd  
from transformers import AutoModelForSeq2SeqLM, AutoModelForTableQuestionAnswering, AutoTokenizer, pipeline 

model_tapas = "google/tapas-large-finetuned-wtq"

tokenizer_tapas = AutoTokenizer.from_pretrained(model_tapas) 
pipe_tapas = pipeline("table-question-answering", model=model_tapas, tokenizer=tokenizer_tapas) 

def process(query, file, correct_answer): 
    table = pd.read_csv(file.name).astype(str).fillna('') 
    #table = table[:rows] if rows else table 
    result_tapas = pipe_tapas(table = table, query = query) 
    return result_tapas['answer']


query_text = gr.Text(label = "Enter a question") 
input_file = gr.File(label = "Upload a CVS file", type = "file") 

# outputs from the app 
answer_text_tapas = gr.Text(label = "TAPAS answer") 

description = """
# Siddharth Test Gradio Table QA
"""

iface = gr.Interface(
    theme="huggingface",
    description=description, 
    fn = process, 
    inputs = [query_text, input_file,], 
    outputs = [answer_text_tapas],
    examples = [["Apps with more than 4.7 rating in art and design?","playstore_text_csv.csv","Harley Quinn wallpapers HD --- ",],
    ["How many apps have Beauty genres?","playstore_text_csv.csv",""],
    ["Average Installs of apps with Beauty genres?","playstore_text_csv.csv",""] ]
     ,
    allow_flagging="never"
)


iface.launch()