Upload src/streamlit_app.py with huggingface_hub
Browse files- src/streamlit_app.py +40 -24
src/streamlit_app.py
CHANGED
|
@@ -103,33 +103,49 @@ if model_option == "Select a single model":
|
|
| 103 |
|
| 104 |
# Main content
|
| 105 |
st.header("Upload Data")
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
if uploaded_files:
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
with st.spinner('Classifying...'):
|
| 111 |
-
# Create a temporary file path
|
| 112 |
-
import tempfile
|
| 113 |
-
import os
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
tmp_file.write(uploaded_file.getvalue())
|
| 118 |
-
tmp_path = tmp_file.name
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
for i, channel in enumerate(channels):
|
| 134 |
image[:, :, i] = data[:, :, channel-1]
|
| 135 |
|
|
|
|
| 103 |
|
| 104 |
# Main content
|
| 105 |
st.header("Upload Data")
|
| 106 |
+
|
| 107 |
+
# Initialize session state for error tracking if not exists
|
| 108 |
+
if 'upload_errors' not in st.session_state:
|
| 109 |
+
st.session_state.upload_errors = []
|
| 110 |
+
|
| 111 |
+
uploaded_files = st.file_uploader(
|
| 112 |
+
"Choose .h5 files...",
|
| 113 |
+
type="h5",
|
| 114 |
+
accept_multiple_files=True,
|
| 115 |
+
help="Upload your .h5 files here. Maximum file size is 200MB."
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
if uploaded_files:
|
| 119 |
+
for uploaded_file in uploaded_files:
|
| 120 |
+
st.write(f"Processing file: {uploaded_file.name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
# Display file details for debugging
|
| 123 |
+
st.write(f"File size: {uploaded_file.size} bytes")
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
with st.spinner('Classifying...'):
|
| 126 |
+
try:
|
| 127 |
+
# Read the file directly using BytesIO
|
| 128 |
+
import io
|
| 129 |
+
bytes_data = uploaded_file.getvalue()
|
| 130 |
+
bytes_io = io.BytesIO(bytes_data)
|
| 131 |
+
|
| 132 |
+
with h5py.File(bytes_io, 'r') as hdf:
|
| 133 |
+
# Check if 'img' exists in the file
|
| 134 |
+
if 'img' not in hdf:
|
| 135 |
+
st.error(f"Error: 'img' dataset not found in {uploaded_file.name}")
|
| 136 |
+
continue
|
| 137 |
+
|
| 138 |
+
data = np.array(hdf.get('img'))
|
| 139 |
+
data[np.isnan(data)] = 0.000001
|
| 140 |
+
channels = config["dataset_config"]["channels"]
|
| 141 |
+
image = np.zeros((128, 128, len(channels)))
|
| 142 |
+
|
| 143 |
+
except h5py.Error as he:
|
| 144 |
+
st.error(f"H5PY Error processing {uploaded_file.name}: {str(he)}")
|
| 145 |
+
continue
|
| 146 |
+
except Exception as e:
|
| 147 |
+
st.error(f"Error processing {uploaded_file.name}: {str(e)}")
|
| 148 |
+
continue
|
| 149 |
for i, channel in enumerate(channels):
|
| 150 |
image[:, :, i] = data[:, :, channel-1]
|
| 151 |
|