nlpblogs commited on
Commit
611a078
·
verified ·
1 Parent(s): 06675ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -29,7 +29,9 @@ expander.write('''
29
  To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
30
 
31
  **File Handling and Errors:**
32
- (a) The app may provide an inaccurate answer, if the information is missing from the relevant cell. (b) The app may display an error message if your file has errors or date values.
 
 
33
 
34
  For any errors or inquiries, please contact us at [email protected]
35
 
@@ -50,6 +52,7 @@ max_attempts = 5
50
 
51
 
52
  upload_file = st.file_uploader("Upload your file. Accepted file formats include: .csv, .xlsx", type=['csv', 'xlsx'])
 
53
  if upload_file is not None:
54
  file_extension = upload_file.name.split('.')[-1].lower()
55
  try:
@@ -61,36 +64,34 @@ if upload_file is not None:
61
  st.warning("Unsupported file type.")
62
  st.stop()
63
 
64
- # Convert float columns to integers if they contain whole numbers
65
- for col in df_original.columns:
66
- df_original[col] = df_original[col].astype(int)
67
-
68
  if df_original.isnull().values.any():
69
  st.error("Error: The file contains missing values.")
70
  st.stop()
71
  else:
72
- st.session_state.df_original = df_original
73
 
74
  all_columns = df_original.columns.tolist()
75
  st.subheader("Select columns from your data to visualize it in a tree map", divider="blue")
76
  parent_column = st.selectbox("Select the parent column:", all_columns)
77
  value_column = st.selectbox("Select the value column:", all_columns)
 
78
  if parent_column and value_column:
79
  if parent_column == value_column:
80
  st.warning("Warning: You have selected the same column for both the parent and value column. Please select two different columns from your data.")
81
  else:
82
- df_treemap = df_original.copy()
83
-
84
  path_columns = [px.Constant("all"), parent_column, value_column]
85
  fig = px.treemap(df_treemap,
86
  path=path_columns)
87
  fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
88
  st.subheader("Tree map", divider="blue")
89
  st.plotly_chart(fig)
 
90
  st.subheader("Uploaded File", divider="blue")
91
  st.dataframe(df_original, key="uploaded_dataframe")
92
  st.write(f"_Number of rows_: {df_original.shape[0]}")
93
  st.write(f"_Number of columns_: {df_original.shape[1]}")
 
94
  except pd.errors.ParserError:
95
  st.error("Error: The CSV file is not readable or is incorrectly formatted.")
96
  st.stop()
@@ -103,9 +104,8 @@ if upload_file is not None:
103
  except Exception as e:
104
  st.error(f"An unexpected error occurred: {e}")
105
  st.stop()
106
- st.divider()
107
-
108
 
 
109
 
110
 
111
  def clear_question():
@@ -128,4 +128,6 @@ if st.button("Retrieve your answer"):
128
  st.write(tqa(table=df_original, query=question)['answer'])
129
 
130
  st.divider()
131
- st.write(f"Number of questions asked: {st.session_state['question_attempts']}/{max_attempts}")
 
 
 
29
  To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
30
 
31
  **File Handling and Errors:**
32
+ The app may provide an inaccurate answer, if the information is missing from the relevant cell.
33
+
34
+ The app may display an error message if your file has errors, date values or float numbers (0.5, 1.2, 4.5 etc.)
35
 
36
  For any errors or inquiries, please contact us at [email protected]
37
 
 
52
 
53
 
54
  upload_file = st.file_uploader("Upload your file. Accepted file formats include: .csv, .xlsx", type=['csv', 'xlsx'])
55
+
56
  if upload_file is not None:
57
  file_extension = upload_file.name.split('.')[-1].lower()
58
  try:
 
64
  st.warning("Unsupported file type.")
65
  st.stop()
66
 
 
 
 
 
67
  if df_original.isnull().values.any():
68
  st.error("Error: The file contains missing values.")
69
  st.stop()
70
  else:
71
+ st.session_state.df_original = df_original
72
 
73
  all_columns = df_original.columns.tolist()
74
  st.subheader("Select columns from your data to visualize it in a tree map", divider="blue")
75
  parent_column = st.selectbox("Select the parent column:", all_columns)
76
  value_column = st.selectbox("Select the value column:", all_columns)
77
+
78
  if parent_column and value_column:
79
  if parent_column == value_column:
80
  st.warning("Warning: You have selected the same column for both the parent and value column. Please select two different columns from your data.")
81
  else:
82
+ df_treemap = df_original.copy()
 
83
  path_columns = [px.Constant("all"), parent_column, value_column]
84
  fig = px.treemap(df_treemap,
85
  path=path_columns)
86
  fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
87
  st.subheader("Tree map", divider="blue")
88
  st.plotly_chart(fig)
89
+
90
  st.subheader("Uploaded File", divider="blue")
91
  st.dataframe(df_original, key="uploaded_dataframe")
92
  st.write(f"_Number of rows_: {df_original.shape[0]}")
93
  st.write(f"_Number of columns_: {df_original.shape[1]}")
94
+
95
  except pd.errors.ParserError:
96
  st.error("Error: The CSV file is not readable or is incorrectly formatted.")
97
  st.stop()
 
104
  except Exception as e:
105
  st.error(f"An unexpected error occurred: {e}")
106
  st.stop()
 
 
107
 
108
+ st.divider()
109
 
110
 
111
  def clear_question():
 
128
  st.write(tqa(table=df_original, query=question)['answer'])
129
 
130
  st.divider()
131
+ st.write(f"Number of questions asked: {st.session_state['question_attempts']}/{max_attempts}")
132
+
133
+