Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 9 |
-
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
|
| 14 |
-
#
|
| 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)
|