Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| # Simple app: convert user input into ASCII codes and binary labels | |
| def string_to_binary_labels(s: str) -> list[int]: | |
| """ | |
| Convert a string into a flat list of binary labels (0 or 1) representing | |
| each character's 8-bit ASCII code. | |
| """ | |
| bits: list[int] = [] | |
| for char in s: | |
| ascii_code = ord(char) | |
| # Extract 8-bit binary representation (MSB first) | |
| char_bits = [(ascii_code >> bit) & 1 for bit in range(7, -1, -1)] | |
| bits.extend(char_bits) | |
| return bits | |
| st.title("ASCII & Binary Label Converter") | |
| st.write("Enter text to see its ASCII codes and corresponding binary labels:") | |
| user_input = st.text_input("Text Input", value="DNA") | |
| if user_input: | |
| # Compute ASCII codes | |
| ascii_codes = [ord(c) for c in user_input] | |
| # Compute binary labels | |
| binary_labels = string_to_binary_labels(user_input) | |
| st.subheader("ASCII Codes") | |
| st.write(ascii_codes) | |
| st.subheader("Binary Labels") | |
| # Display bits grouped per character for readability | |
| grouped = [binary_labels[i:i+8] for i in range(0, len(binary_labels), 8)] | |
| for idx, bits in enumerate(grouped): | |
| st.write(f"'{user_input[idx]}' → {bits}") | |
| st.download_button( | |
| label="Download Binary Labels as CSV", | |
| data=','.join(str(b) for b in binary_labels), | |
| file_name="binary_labels.csv", | |
| mime="text/csv" | |
| ) | |
| # Future: integrate DNA editor mapping for each mutation site here | |