Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,12 +13,16 @@ df['real'] = df['real'].apply(lambda x: f"{x:.2f}")
|
|
13 |
# Fill NaN values and convert all columns to strings
|
14 |
df = df.fillna('').astype(str)
|
15 |
|
16 |
-
#
|
|
|
|
|
|
|
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)
|
@@ -26,8 +30,12 @@ def response(user_question, df):
|
|
26 |
print("User question:", user_question)
|
27 |
|
28 |
# Query the TAPAS model
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
query_result = {
|
32 |
"Resposta": answer
|
33 |
}
|
|
|
13 |
# Fill NaN values and convert all columns to strings
|
14 |
df = df.fillna('').astype(str)
|
15 |
|
16 |
+
# Ensure that the 'Group' column doesn't have excessive length or unexpected values
|
17 |
+
df['Group'] = df['Group'].str.slice(0, 255) # Truncate to 255 characters if needed
|
18 |
+
|
19 |
+
# Function to generate a response using the TAPEX model
|
20 |
def response(user_question, df):
|
21 |
a = datetime.datetime.now()
|
22 |
|
23 |
# Initialize the TAPAS model
|
24 |
+
tqa = pipeline(task="table-question-answering", model="google/tapas-large-finetuned-wtq",
|
25 |
+
tokenizer_kwargs={"clean_up_tokenization_spaces": False})
|
26 |
|
27 |
# Debugging information
|
28 |
print("DataFrame shape:", df.shape)
|
|
|
30 |
print("User question:", user_question)
|
31 |
|
32 |
# Query the TAPAS model
|
33 |
+
try:
|
34 |
+
answer = tqa(table=df, query=user_question)['answer']
|
35 |
+
except IndexError as e:
|
36 |
+
print(f"Error: {e}")
|
37 |
+
answer = "Error occurred: " + str(e)
|
38 |
+
|
39 |
query_result = {
|
40 |
"Resposta": answer
|
41 |
}
|