CosmickVisions commited on
Commit
d3ea99a
·
verified ·
1 Parent(s): b0c63cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -42,6 +42,12 @@ def preprocess_image(image_path, target_size=(224, 224)):
42
 
43
  def load_image_dataset(zip_path, target_size=(224, 224), problem_type="Classification"):
44
  """Load and preprocess an image dataset from a zip file."""
 
 
 
 
 
 
45
  # Extract zip file to a temporary directory
46
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
47
  zip_ref.extractall('temp_images')
@@ -365,17 +371,25 @@ if app_mode == "Data Upload":
365
  with col2: st.metric("Columns", df.shape[1])
366
  with col3: st.metric("Missing Values", df.isna().sum().sum())
367
  else: # Image
368
- uploaded_file = st.file_uploader("Upload Zip File with Images", type=["zip"])
369
  if uploaded_file:
370
- problem_type = st.selectbox("Problem Type for Image Data", ["Image Classification", "Compression", "Clustering"])
371
- images, labels, class_names = load_image_dataset(uploaded_file, problem_type=problem_type)
372
- st.session_state.images = images
373
- st.session_state.labels = labels
374
- st.session_state.class_names = class_names if problem_type == "Image Classification" else None
375
- st.write(f"Loaded {len(images)} images.")
376
- if problem_type == "Image Classification":
377
- st.write(f"Classes: {class_names}")
378
- st.image(images[:5], caption=["Sample " + str(i+1) for i in range(min(5, len(images)))], width=100)
 
 
 
 
 
 
 
 
379
 
380
  elif app_mode == "Model Training":
381
  st.title("🧠 Model Training")
 
42
 
43
  def load_image_dataset(zip_path, target_size=(224, 224), problem_type="Classification"):
44
  """Load and preprocess an image dataset from a zip file."""
45
+ # Check file size (5GB = 5 * 1024 * 1024 * 1024 bytes)
46
+ file_size = os.path.getsize(zip_path) if isinstance(zip_path, str) else zip_path.size
47
+ max_size = 5 * 1024 * 1024 * 1024 # 5GB in bytes
48
+ if file_size > max_size:
49
+ raise ValueError(f"Uploaded file size ({file_size / (1024 * 1024):.2f} MB) exceeds the 5GB limit.")
50
+
51
  # Extract zip file to a temporary directory
52
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
53
  zip_ref.extractall('temp_images')
 
371
  with col2: st.metric("Columns", df.shape[1])
372
  with col3: st.metric("Missing Values", df.isna().sum().sum())
373
  else: # Image
374
+ uploaded_file = st.file_uploader("Upload Zip File with Images (Max 5GB)", type=["zip"])
375
  if uploaded_file:
376
+ # Save uploaded file temporarily to check size
377
+ with open("temp_upload.zip", "wb") as f:
378
+ f.write(uploaded_file.getbuffer())
379
+ try:
380
+ problem_type = st.selectbox("Problem Type for Image Data", ["Image Classification", "Compression", "Clustering"])
381
+ images, labels, class_names = load_image_dataset("temp_upload.zip", problem_type=problem_type)
382
+ st.session_state.images = images
383
+ st.session_state.labels = labels
384
+ st.session_state.class_names = class_names if problem_type == "Image Classification" else None
385
+ st.write(f"Loaded {len(images)} images.")
386
+ if problem_type == "Image Classification":
387
+ st.write(f"Classes: {class_names}")
388
+ st.image(images[:5], caption=["Sample " + str(i+1) for i in range(min(5, len(images)))], width=100)
389
+ except ValueError as e:
390
+ st.error(str(e))
391
+ finally:
392
+ os.remove("temp_upload.zip")
393
 
394
  elif app_mode == "Model Training":
395
  st.title("🧠 Model Training")