Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -54,7 +54,10 @@ else:
|
|
54 |
if df is not None:
|
55 |
numeric_columns = df.select_dtypes(include=['object']).columns
|
56 |
for col in numeric_columns:
|
57 |
-
|
|
|
|
|
|
|
58 |
|
59 |
st.write("Original Data:")
|
60 |
st.write(df)
|
@@ -65,10 +68,10 @@ else:
|
|
65 |
# Display the first 5 rows of the dataframe in an editable grid
|
66 |
grid_response = AgGrid(
|
67 |
df.head(5),
|
68 |
-
columns_auto_size_mode='FIT_CONTENTS',
|
69 |
editable=True,
|
70 |
height=300,
|
71 |
width='100%',
|
|
|
72 |
)
|
73 |
|
74 |
except Exception as e:
|
@@ -94,8 +97,6 @@ else:
|
|
94 |
columns = question.split('between')[-1].split('and')
|
95 |
columns = [col.strip() for col in columns]
|
96 |
if len(columns) == 2 and all(col in df.columns for col in columns):
|
97 |
-
# Debugging log
|
98 |
-
st.write(f"Generating graph for columns: {columns[0]} and {columns[1]}") # Debug statement
|
99 |
fig = px.scatter(df, x=columns[0], y=columns[1], title=f"Graph between {columns[0]} and {columns[1]}")
|
100 |
st.plotly_chart(fig, use_container_width=True)
|
101 |
st.success(f"Here is the graph between '{columns[0]}' and '{columns[1]}'.")
|
@@ -104,16 +105,14 @@ else:
|
|
104 |
elif 'column' in question.lower():
|
105 |
column = question.split('of')[-1].strip()
|
106 |
if column in df.columns:
|
107 |
-
# Debugging log
|
108 |
-
st.write(f"Generating graph for column: {column}") # Debug statement
|
109 |
fig = px.line(df, x=df.index, y=column, title=f"Graph of column '{column}'")
|
110 |
st.plotly_chart(fig, use_container_width=True)
|
111 |
st.success(f"Here is the graph of column '{column}'.")
|
112 |
else:
|
113 |
st.warning(f"Column '{column}' not found in the data.")
|
114 |
|
115 |
-
#
|
116 |
-
st.stop() #
|
117 |
|
118 |
# Process TAPAS-related questions if it's not a graph query
|
119 |
raw_answer = tqa(table=df, query=question, truncation=True)
|
|
|
54 |
if df is not None:
|
55 |
numeric_columns = df.select_dtypes(include=['object']).columns
|
56 |
for col in numeric_columns:
|
57 |
+
try:
|
58 |
+
df[col] = pd.to_numeric(df[col])
|
59 |
+
except ValueError:
|
60 |
+
st.warning(f"Column '{col}' contains non-numeric values that could not be converted.")
|
61 |
|
62 |
st.write("Original Data:")
|
63 |
st.write(df)
|
|
|
68 |
# Display the first 5 rows of the dataframe in an editable grid
|
69 |
grid_response = AgGrid(
|
70 |
df.head(5),
|
|
|
71 |
editable=True,
|
72 |
height=300,
|
73 |
width='100%',
|
74 |
+
fit_columns_on_grid_load=True # Correct option for auto-sizing
|
75 |
)
|
76 |
|
77 |
except Exception as e:
|
|
|
97 |
columns = question.split('between')[-1].split('and')
|
98 |
columns = [col.strip() for col in columns]
|
99 |
if len(columns) == 2 and all(col in df.columns for col in columns):
|
|
|
|
|
100 |
fig = px.scatter(df, x=columns[0], y=columns[1], title=f"Graph between {columns[0]} and {columns[1]}")
|
101 |
st.plotly_chart(fig, use_container_width=True)
|
102 |
st.success(f"Here is the graph between '{columns[0]}' and '{columns[1]}'.")
|
|
|
105 |
elif 'column' in question.lower():
|
106 |
column = question.split('of')[-1].strip()
|
107 |
if column in df.columns:
|
|
|
|
|
108 |
fig = px.line(df, x=df.index, y=column, title=f"Graph of column '{column}'")
|
109 |
st.plotly_chart(fig, use_container_width=True)
|
110 |
st.success(f"Here is the graph of column '{column}'.")
|
111 |
else:
|
112 |
st.warning(f"Column '{column}' not found in the data.")
|
113 |
|
114 |
+
# Skip the TAPAS processing if it's a graph query
|
115 |
+
st.stop() # This ensures the code halts and avoids further processing
|
116 |
|
117 |
# Process TAPAS-related questions if it's not a graph query
|
118 |
raw_answer = tqa(table=df, query=question, truncation=True)
|