wenjun99 commited on
Commit
c34e683
·
verified ·
1 Parent(s): 7e8c2cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -110,12 +110,32 @@ if binary_file:
110
  df_binary = pd.read_csv(binary_file, header=None)
111
  df_binary.columns = [str(i+1) for i in range(df_binary.shape[1])]
112
  else:
113
- st.info("No file uploaded — manually enter binary data below.")
 
 
 
 
 
 
 
 
 
 
 
 
114
  df_binary = st.data_editor(
115
- pd.DataFrame(columns=[str(i) for i in range(1, 20)]),
116
- num_rows="dynamic", key="manual_input"
 
 
117
  )
118
 
 
 
 
 
 
 
119
  if not df_binary.empty:
120
  st.subheader("Binary Matrix")
121
  st.dataframe(df_binary.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
 
110
  df_binary = pd.read_csv(binary_file, header=None)
111
  df_binary.columns = [str(i+1) for i in range(df_binary.shape[1])]
112
  else:
113
+ st.info("No file uploaded — manually enter or paste your binary data below.")
114
+ st.caption("💡 Tip: You can copy and paste entire datasets (Ctrl+V) directly here — rows and columns will adjust automatically.")
115
+
116
+ # Ask the user how many columns (if they want to define manually)
117
+ n_cols = st.number_input(
118
+ "Number of columns (adjust if pasting a dataset)",
119
+ min_value=1, value=8, step=1
120
+ )
121
+
122
+ # Create an empty DataFrame with that many columns
123
+ initial_df = pd.DataFrame(columns=[str(i) for i in range(1, n_cols + 1)])
124
+
125
+ # Dynamic editor — allows copy-paste of arbitrary rows
126
  df_binary = st.data_editor(
127
+ initial_df,
128
+ num_rows="dynamic",
129
+ key="manual_input",
130
+ use_container_width=True,
131
  )
132
 
133
+ # If user pastes a larger dataset (more columns than n_cols)
134
+ # detect and rename automatically
135
+ if not df_binary.empty:
136
+ n_detected = df_binary.shape[1]
137
+ df_binary.columns = [str(i+1) for i in range(n_detected)]
138
+
139
  if not df_binary.empty:
140
  st.subheader("Binary Matrix")
141
  st.dataframe(df_binary.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))