hertogateis commited on
Commit
879d20e
·
verified ·
1 Parent(s): 4665c84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -3,6 +3,22 @@ import streamlit as st
3
  from transformers import TapasForQuestionAnswering, TapasTokenizer, T5ForConditionalGeneration, T5Tokenizer
4
  import torch
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # Load TAPAS model and tokenizer
7
  tqa_model = TapasForQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")
8
  tqa_tokenizer = TapasTokenizer.from_pretrained("google/tapas-large-finetuned-wtq")
@@ -11,9 +27,6 @@ tqa_tokenizer = TapasTokenizer.from_pretrained("google/tapas-large-finetuned-wtq
11
  t5_model = T5ForConditionalGeneration.from_pretrained("t5-small")
12
  t5_tokenizer = T5Tokenizer.from_pretrained("t5-small")
13
 
14
- # Assuming 'df' is the DataFrame you are using and has numeric columns
15
- df_numeric = df.select_dtypes(include='number')
16
-
17
  # User input for the question
18
  question = st.text_input('Type your question')
19
 
@@ -60,6 +73,10 @@ with st.spinner():
60
  st.warning("Please retype your question and make sure to use the column name and cell value correctly.")
61
 
62
 
 
 
 
 
63
  # Manually fix the aggregator if it returns an incorrect one
64
  if 'MEDIAN' in question.upper() and 'AVERAGE' in aggregator.upper():
65
  aggregator = 'MEDIAN'
 
3
  from transformers import TapasForQuestionAnswering, TapasTokenizer, T5ForConditionalGeneration, T5Tokenizer
4
  import torch
5
 
6
+ # Assuming df is uploaded or pre-defined (you can replace with actual data loading logic)
7
+ # Example DataFrame (replace with your actual file or data)
8
+ data = {
9
+ 'Column1': [1, 2, 3, 4],
10
+ 'Column2': [5.5, 6.5, 7.5, 8.5],
11
+ 'Column3': ['a', 'b', 'c', 'd']
12
+ }
13
+ df = pd.DataFrame(data)
14
+
15
+ # Check if DataFrame is valid
16
+ if df is not None and not df.empty:
17
+ # Select numeric columns
18
+ df_numeric = df.select_dtypes(include='number')
19
+ else:
20
+ df_numeric = pd.DataFrame() # Empty DataFrame if input is invalid
21
+
22
  # Load TAPAS model and tokenizer
23
  tqa_model = TapasForQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")
24
  tqa_tokenizer = TapasTokenizer.from_pretrained("google/tapas-large-finetuned-wtq")
 
27
  t5_model = T5ForConditionalGeneration.from_pretrained("t5-small")
28
  t5_tokenizer = T5Tokenizer.from_pretrained("t5-small")
29
 
 
 
 
30
  # User input for the question
31
  question = st.text_input('Type your question')
32
 
 
73
  st.warning("Please retype your question and make sure to use the column name and cell value correctly.")
74
 
75
 
76
+ # Assuming 'column_name' exists and is selected or provided by the user
77
+ # Example of getting 'column_name' from user input (adjust this part according to your app):
78
+ column_name = st.selectbox("Select a column", df.columns)
79
+
80
  # Manually fix the aggregator if it returns an incorrect one
81
  if 'MEDIAN' in question.upper() and 'AVERAGE' in aggregator.upper():
82
  aggregator = 'MEDIAN'