Update app.py
Browse files
app.py
CHANGED
@@ -54,29 +54,33 @@ def answer_query_from_csv(query, file):
|
|
54 |
# Read the file into a DataFrame
|
55 |
table_data = pd.read_csv(file)
|
56 |
|
57 |
-
# Convert object-type columns
|
58 |
for column in table_data.columns:
|
59 |
-
if table_data[column].dtype == 'object':
|
60 |
table_data[column] = table_data[column].apply(lambda x: x.lower() if isinstance(x, str) else x)
|
61 |
|
62 |
-
|
|
|
|
|
63 |
for column in table_data.columns:
|
64 |
if pd.api.types.is_datetime64_any_dtype(table_data[column]):
|
65 |
table_data[f'{column}_year'] = table_data[column].dt.year
|
66 |
table_data[f'{column}_month'] = table_data[column].dt.month
|
67 |
table_data[f'{column}_day'] = table_data[column].dt.day
|
68 |
table_data[f'{column}_time'] = table_data[column].dt.strftime('%H:%M:%S')
|
69 |
-
|
70 |
-
|
|
|
71 |
result_tapex = process_table_query(query, table_data)
|
72 |
|
73 |
-
# Process the query using TAPAS pipelines
|
74 |
result_tapas = pipe_tapas(table=table_data, query=query)['cells'][0]
|
75 |
result_tapas2 = pipe_tapas2(table=table_data, query=query)['cells'][0]
|
76 |
|
77 |
return result_tapex, result_tapas, result_tapas2
|
78 |
|
79 |
|
|
|
80 |
# Create Gradio interface
|
81 |
with gr.Blocks() as interface:
|
82 |
gr.Markdown("# Table Question Answering with TAPEX and TAPAS Models")
|
|
|
54 |
# Read the file into a DataFrame
|
55 |
table_data = pd.read_csv(file)
|
56 |
|
57 |
+
# Convert object-type columns to lowercase, ensuring only valid strings are affected
|
58 |
for column in table_data.columns:
|
59 |
+
if table_data[column].dtype == 'object':
|
60 |
table_data[column] = table_data[column].apply(lambda x: x.lower() if isinstance(x, str) else x)
|
61 |
|
62 |
+
|
63 |
+
|
64 |
+
# Extract year, month, day, and time components for datetime columns
|
65 |
for column in table_data.columns:
|
66 |
if pd.api.types.is_datetime64_any_dtype(table_data[column]):
|
67 |
table_data[f'{column}_year'] = table_data[column].dt.year
|
68 |
table_data[f'{column}_month'] = table_data[column].dt.month
|
69 |
table_data[f'{column}_day'] = table_data[column].dt.day
|
70 |
table_data[f'{column}_time'] = table_data[column].dt.strftime('%H:%M:%S')
|
71 |
+
# Ensure all data in the table is converted to string
|
72 |
+
table_data = table_data.astype(str)
|
73 |
+
# Process the CSV file and query using TAPEX
|
74 |
result_tapex = process_table_query(query, table_data)
|
75 |
|
76 |
+
# Process the query using TAPAS pipelines (ensure all cells are strings)
|
77 |
result_tapas = pipe_tapas(table=table_data, query=query)['cells'][0]
|
78 |
result_tapas2 = pipe_tapas2(table=table_data, query=query)['cells'][0]
|
79 |
|
80 |
return result_tapex, result_tapas, result_tapas2
|
81 |
|
82 |
|
83 |
+
|
84 |
# Create Gradio interface
|
85 |
with gr.Blocks() as interface:
|
86 |
gr.Markdown("# Table Question Answering with TAPEX and TAPAS Models")
|