spacr 0.3.47__py3-none-any.whl → 0.3.50__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
spacr/chat_bot.py ADDED
@@ -0,0 +1,31 @@
1
+ import os
2
+ import torch
3
+ from multiprocessing import Queue
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+
6
+ # Disable parallelism warnings
7
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
8
+
9
+ def load_model(model_queue):
10
+ """Load the Falcon-7B model and send the status via a queue."""
11
+ try:
12
+ print("Loading Falcon-7B model...")
13
+ tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b")
14
+
15
+ # Set `pad_token` to `eos_token` if not already set
16
+ if tokenizer.pad_token is None:
17
+ tokenizer.pad_token = tokenizer.eos_token
18
+
19
+ model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-7b")
20
+ model.config.pad_token_id = tokenizer.pad_token_id
21
+
22
+ # Send the loaded model and tokenizer back via the queue
23
+ model_queue.put((model, tokenizer, "Model loaded successfully!"))
24
+ except Exception as e:
25
+ model_queue.put((None, None, f"Error loading model: {e}"))
26
+
27
+ def language_chat(tokenizer, model, user_input):
28
+ inputs = tokenizer(user_input, return_tensors="pt", padding=True, truncation=True)
29
+ outputs = model.generate(inputs.input_ids, max_length=256, pad_token_id=tokenizer.eos_token_id)
30
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
31
+
spacr/gui_elements.py CHANGED
@@ -16,7 +16,8 @@ from collections import deque
16
16
  from skimage.draw import polygon, line
17
17
  from skimage.transform import resize
18
18
  from scipy.ndimage import binary_fill_holes, label
19
- from tkinter import ttk, scrolledtext
19
+ from tkinter import ttk, scrolledtext
20
+ from skimage.color import rgb2gray
20
21
 
21
22
  fig = None
22
23
 
@@ -1534,20 +1535,45 @@ class ModifyMaskApp:
1534
1535
  tk.Label(self.zoom_toolbar, text="Upper Percentile:", bg='black', fg='white').pack(side='left')
1535
1536
  self.upper_entry = tk.Entry(self.zoom_toolbar, textvariable=self.upper_quantile, bg='black', fg='white')
1536
1537
  self.upper_entry.pack(side='left')
1537
-
1538
-
1538
+
1539
1539
  def load_image_and_mask(self, index):
1540
+ # Load the image
1540
1541
  image_path = os.path.join(self.folder_path, self.image_filenames[index])
1541
- image = imageio.imread(image_path)
1542
+ image = imageio.imread(image_path)
1543
+ print(f"Original Image shape: {image.shape}, dtype: {image.dtype}")
1544
+
1545
+ # Handle multi-channel or transparency issues
1546
+ if image.ndim == 3:
1547
+ if image.shape[2] == 4: # If the image has an alpha channel (RGBA)
1548
+ image = image[..., :3] # Remove the alpha channel
1549
+
1550
+ # Convert RGB to grayscale using weighted average
1551
+ image = np.dot(image[..., :3], [0.2989, 0.5870, 0.1140]).astype(np.uint8)
1552
+ print(f"Converted to grayscale: {image.shape}")
1553
+
1554
+ # Ensure the shape is (height, width) without extra channel
1555
+ if image.ndim == 3 and image.shape[2] == 1:
1556
+ image = np.squeeze(image, axis=-1)
1557
+
1558
+ if image.dtype != np.uint16:
1559
+ # Scale the image to fit the 16-bit range (0–65535)
1560
+ image = (image / image.max() * 65535).astype(np.uint16)
1561
+ # eventually remove this images should not have to be 16 bit look into downstream function (non 16bit images are jsut black)
1562
+
1563
+ # Load the corresponding mask
1542
1564
  mask_path = os.path.join(self.masks_folder, self.image_filenames[index])
1543
1565
  if os.path.exists(mask_path):
1544
- print(f'loading mask:{mask_path} for image: {image_path}')
1566
+ print(f'Loading mask: {mask_path} for image: {image_path}')
1545
1567
  mask = imageio.imread(mask_path)
1568
+
1569
+ # Ensure mask is uint8
1546
1570
  if mask.dtype != np.uint8:
1547
- mask = (mask / np.max(mask) * 255).astype(np.uint8)
1571
+ mask = (mask / mask.max() * 255).astype(np.uint8)
1548
1572
  else:
1573
+ # Create a new mask with the same size as the image
1549
1574
  mask = np.zeros(image.shape[:2], dtype=np.uint8)
1550
- print(f'loaded new mask for image: {image_path}')
1575
+ print(f'Loaded new mask for image: {image_path}')
1576
+
1551
1577
  return image, mask
1552
1578
 
1553
1579
  ####################################################################################################