fschwartzer commited on
Commit
6c96c7d
1 Parent(s): 0850865

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import streamlit as st
2
  import pandas as pd
 
3
  from transformers import pipeline
 
4
 
5
  df = pd.read_excel('discrepantes.xlsx', index_col='Unnamed: 0')
6
  df.fillna(0, inplace=True)
@@ -8,9 +10,17 @@ table_data = df.astype(str)
8
  print(table_data.head())
9
 
10
  def response(user_question, table_data):
11
- tqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq")
12
- resposta = tqa(table=table_data , query=user_question)['cells'][0]
13
- return resposta
 
 
 
 
 
 
 
 
14
 
15
  # Streamlit interface
16
  st.markdown("""
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import torch
4
  from transformers import pipeline
5
+ from transformers import TapasTokenizer, TapasForQuestionAnswering
6
 
7
  df = pd.read_excel('discrepantes.xlsx', index_col='Unnamed: 0')
8
  df.fillna(0, inplace=True)
 
10
  print(table_data.head())
11
 
12
  def response(user_question, table_data):
13
+ tokenizer = TapasTokenizer.from_pretrained("google/tapas-large-finetuned-wtq", drop_rows_to_fit=True)
14
+ model = TapasForQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")
15
+
16
+ inputs = tokenizer(table=table_data, queries=user_question, padding="max_length", truncation=True, return_tensors="pt")
17
+ outputs = model(**inputs)
18
+
19
+ predicted_answer_coordinates = outputs.predicted_answer_coordinates.detach().cpu().numpy()
20
+ id2aggregation = {0: 'NONE', 1: 'SUM', 2: 'AVERAGE', 3: 'COUNT'}
21
+ aggregation_predictions = id2aggregation[outputs.aggregation_predictions.detach().cpu().numpy()[0]]
22
+
23
+ return predicted_answer_coordinates, aggregation_predictions
24
 
25
  # Streamlit interface
26
  st.markdown("""