Spaces:
Runtime error
Runtime error
new
Browse files
pages/Model_Evaluation.py
CHANGED
|
@@ -61,15 +61,20 @@ def apply_gaussian_filter(image, kernel_size=(5, 5), sigma=1.0):
|
|
| 61 |
|
| 62 |
# ---- Custom Dataset ----
|
| 63 |
def __getitem__(self, idx):
|
| 64 |
-
|
|
|
|
| 65 |
label = int(self.labels[idx])
|
| 66 |
|
|
|
|
|
|
|
|
|
|
| 67 |
try:
|
| 68 |
print(f"Downloading: {img_url}")
|
| 69 |
-
response = requests.get(img_url)
|
| 70 |
if response.status_code != 200:
|
| 71 |
raise ValueError(f"Failed to download image from {img_url} - status code: {response.status_code}")
|
| 72 |
|
|
|
|
| 73 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 74 |
except Exception as e:
|
| 75 |
raise RuntimeError(f"Error loading image from {img_url}: {e}")
|
|
|
|
| 61 |
|
| 62 |
# ---- Custom Dataset ----
|
| 63 |
def __getitem__(self, idx):
|
| 64 |
+
# Get the image URL and label
|
| 65 |
+
raw_url = self.image_paths[idx]
|
| 66 |
label = int(self.labels[idx])
|
| 67 |
|
| 68 |
+
# Fix the URL if it's in blob format
|
| 69 |
+
img_url = raw_url.replace("/blob/", "/resolve/")
|
| 70 |
+
|
| 71 |
try:
|
| 72 |
print(f"Downloading: {img_url}")
|
| 73 |
+
response = requests.get(img_url, stream=True)
|
| 74 |
if response.status_code != 200:
|
| 75 |
raise ValueError(f"Failed to download image from {img_url} - status code: {response.status_code}")
|
| 76 |
|
| 77 |
+
# Read and convert the image
|
| 78 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 79 |
except Exception as e:
|
| 80 |
raise RuntimeError(f"Error loading image from {img_url}: {e}")
|