File size: 1,035 Bytes
84e78bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import pandas as pd

def TAPAS(question, table_main):
    """
    Processing the question using an expression and the main and geom table.

    Args:
        question (str): the question.
        table_main (df): main table
        table_geom (df): geom table
    Returns:
        answer (str): answer to the question
    """
    
    # set up a TAPAS pipeline for table-based question answering
    tqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq")

    # use the tqa pipeline to perform table-based question answering.
    i = tqa(table=table_main, query=question)['cells'][0]

    # Check if the output is the link to the TEMP DB:
    # Has to be done because the entrys for geometry, ... are an array :(
    if ';' in i:
        i = i.split(";")
        path = i[0]
        r = int(i[1])
        c = int(i[2])
        answer_table = pd.read_csv(path)
        answer = answer_table.iloc[r,c]
        return(answer)
    
    answer = str(i)
    return(answer)