Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 116 |
-
num_rows="dynamic",
|
|
|
|
|
|
|
| 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"))
|