fschwartzer commited on
Commit
57c5821
β€’
1 Parent(s): 5f82549

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -3,31 +3,29 @@ import pandas as pd
3
  import torch
4
  from transformers import pipeline
5
  import datetime
6
- #from datasets import load_dataset
7
 
8
- #dataset = load_dataset("wikitablequestions", trust_remote_code=True)
9
- #item = dataset["test"][10] # show first test example
10
 
11
- #def to_pandas(item):
12
- #return pd.DataFrame(item['table']["rows"], columns=item['table']["header"])
13
 
14
- #df = to_pandas(item)
15
- #print(df.head())
16
-
17
- df = pd.read_csv("anomalies.csv",quotechar='"',dtype={col: str for col in pd.read_csv('anomalies.csv', nrows=1)})
18
  df = df.fillna('').astype(str)
19
 
20
-
21
- # Function to generate a response using the TAPEX model
22
  def response(user_question, df):
23
  a = datetime.datetime.now()
24
 
 
25
  tqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq")
26
 
 
27
  print("DataFrame shape:", df.shape)
28
  print("DataFrame head:\n", df.head())
29
  print("User question:", user_question)
30
 
 
31
  answer = tqa(table=df, query=user_question)['answer']
32
 
33
  query_result = {
@@ -35,7 +33,7 @@ def response(user_question, df):
35
  }
36
 
37
  b = datetime.datetime.now()
38
- print(b - a)
39
 
40
  return query_result
41
 
@@ -77,4 +75,4 @@ for sender, message in st.session_state['history']:
77
  if sender == 'πŸ‘€':
78
  st.markdown(f"**πŸ‘€ {message}**")
79
  elif sender == 'πŸ€–':
80
- st.markdown(f"<div style='text-align: right'>**πŸ€– {message}**</div>", unsafe_allow_html=True)
 
3
  import torch
4
  from transformers import pipeline
5
  import datetime
 
6
 
7
+ # Load the CSV file and ensure proper formatting
8
+ df = pd.read_csv("anomalies.csv", quotechar='"')
9
 
10
+ # Convert 'real' column to standard float format
11
+ df['real'] = df['real'].apply(lambda x: f"{x:.2f}")
12
 
13
+ # Fill NaN values and convert all columns to strings
 
 
 
14
  df = df.fillna('').astype(str)
15
 
16
+ # Function to generate a response using the TAPAS model
 
17
  def response(user_question, df):
18
  a = datetime.datetime.now()
19
 
20
+ # Initialize the TAPAS model
21
  tqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq")
22
 
23
+ # Debugging information
24
  print("DataFrame shape:", df.shape)
25
  print("DataFrame head:\n", df.head())
26
  print("User question:", user_question)
27
 
28
+ # Query the TAPAS model
29
  answer = tqa(table=df, query=user_question)['answer']
30
 
31
  query_result = {
 
33
  }
34
 
35
  b = datetime.datetime.now()
36
+ print("Time taken:", b - a)
37
 
38
  return query_result
39
 
 
75
  if sender == 'πŸ‘€':
76
  st.markdown(f"**πŸ‘€ {message}**")
77
  elif sender == 'πŸ€–':
78
+ st.markdown(f"<div style='text-align: right'>**πŸ€– {message}**</div>", unsafe_allow_html=True)