wenjun99 commited on
Commit
f37dc6c
·
verified ·
1 Parent(s): cb5422c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -3
app.py CHANGED
@@ -70,7 +70,7 @@ mutation_site_headers = [
70
  st.title("ASCII & Binary Label Converter")
71
 
72
  # Create tabs
73
- tab1, tab2 = st.tabs(["Text to Binary Labels", "Image to Binary Labels"])
74
 
75
  with tab1:
76
  st.write("Enter text to see its ASCII codes and corresponding binary labels:")
@@ -119,8 +119,8 @@ with tab2:
119
  img = Image.open(uploaded_file)
120
  st.image(img, caption="Uploaded Image", use_column_width=True)
121
 
122
- st.subheader("Crop the image with drag and select")
123
- cropped_img = st_cropper(img, realtime_update=True, box_color='blue', aspect_ratio=None)
124
 
125
  st.image(cropped_img, caption="Cropped Image", use_column_width=True)
126
 
@@ -155,4 +155,34 @@ with tab2:
155
  mime="text/csv"
156
  )
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  # Future: integrate DNA editor mapping for each mutation site here
 
70
  st.title("ASCII & Binary Label Converter")
71
 
72
  # Create tabs
73
+ tab1, tab2, tab3 = st.tabs(["Text to Binary Labels", "Image to Binary Labels", "EF -> Binary"])
74
 
75
  with tab1:
76
  st.write("Enter text to see its ASCII codes and corresponding binary labels:")
 
119
  img = Image.open(uploaded_file)
120
  st.image(img, caption="Uploaded Image", use_column_width=True)
121
 
122
+ st.subheader("Crop the image with drag and select (1:1 aspect ratio)")
123
+ cropped_img = st_cropper(img, realtime_update=True, box_color='blue', aspect_ratio=1.0)
124
 
125
  st.image(cropped_img, caption="Cropped Image", use_column_width=True)
126
 
 
155
  mime="text/csv"
156
  )
157
 
158
+ with tab3:
159
+ st.write("Upload an Editing Frequency CSV or fill in manually:")
160
+ threshold_file = st.file_uploader("Upload Column Threshold CSV", type=["csv"], key="threshold")
161
+ ef_file = st.file_uploader("Upload Editing Frequency CSV", type=["csv"], key="ef")
162
+
163
+ if threshold_file:
164
+ thresholds_df = pd.read_csv(threshold_file, index_col=0)
165
+ thresholds = thresholds_df.squeeze()
166
+
167
+ if ef_file:
168
+ ef_df = pd.read_csv(ef_file)
169
+ else:
170
+ ef_df = pd.DataFrame(columns=thresholds.index if threshold_file else [])
171
+
172
+ edited_df = st.data_editor(ef_df, num_rows="dynamic")
173
+
174
+ if st.button("Convert to Binary Labels"):
175
+ if threshold_file:
176
+ binary_df = edited_df.ge(thresholds).astype(int)
177
+ st.subheader("Binary Labels")
178
+ st.dataframe(binary_df)
179
+ st.download_button(
180
+ label="Download Binary Labels Table as CSV",
181
+ data=binary_df.to_csv(index=False),
182
+ file_name="ef_binary_labels_table.csv",
183
+ mime="text/csv"
184
+ )
185
+ else:
186
+ st.error("Please upload the threshold CSV file first.")
187
+
188
  # Future: integrate DNA editor mapping for each mutation site here