Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2545,19 +2545,26 @@ def get_product_image_path(product_name: str) -> str:
|
|
| 2545 |
def normalize(name):
|
| 2546 |
return re.sub(r'[\s_\.]', '', name).lower()
|
| 2547 |
normalized_name = normalize(product_name)
|
|
|
|
| 2548 |
image_extensions = ['.png', '.jpg', '.jpeg', '.webp']
|
| 2549 |
base_url = "https://amgocus.com/uploads/images/"
|
| 2550 |
-
|
| 2551 |
-
# Log for respiraaidplus.png check
|
| 2552 |
-
if normalized_name == "respiraaidplus":
|
| 2553 |
-
logger.info(f"[Image] Checking cPanel URL for respiraaidplus: {base_url}respiraaidplus.png")
|
| 2554 |
-
# Try normalized name (with dashes preserved)
|
| 2555 |
for ext in image_extensions:
|
| 2556 |
image_url = f"{base_url}{normalized_name}{ext}"
|
| 2557 |
logger.info(f"[Image] Checking normalized image URL: {image_url}")
|
| 2558 |
# For public URLs, assume they are accessible if they start with http
|
| 2559 |
-
# This avoids issues with servers that don't respond properly to bot requests
|
| 2560 |
if image_url.startswith('http'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2561 |
logger.info(f"[Image] Found public image URL: {image_url}")
|
| 2562 |
return image_url
|
| 2563 |
# Fallback: try original name with spaces as %20
|
|
@@ -2565,11 +2572,9 @@ def get_product_image_path(product_name: str) -> str:
|
|
| 2565 |
for ext in image_extensions:
|
| 2566 |
image_url = f"{base_url}{safe_name}{ext}"
|
| 2567 |
logger.info(f"[Image] Checking fallback image URL: {image_url}")
|
| 2568 |
-
# For public URLs, assume they are accessible if they start with http
|
| 2569 |
if image_url.startswith('http'):
|
| 2570 |
logger.info(f"[Image] Found public image URL (legacy): {image_url}")
|
| 2571 |
return image_url
|
| 2572 |
-
# Remove default image fallback
|
| 2573 |
logger.warning(f"[Image] No public image found for product: {product_name}")
|
| 2574 |
return None
|
| 2575 |
except Exception as e:
|
|
|
|
| 2545 |
def normalize(name):
|
| 2546 |
return re.sub(r'[\s_\.]', '', name).lower()
|
| 2547 |
normalized_name = normalize(product_name)
|
| 2548 |
+
logger.info(f"[Image] Normalized product name: '{product_name}' -> '{normalized_name}'")
|
| 2549 |
image_extensions = ['.png', '.jpg', '.jpeg', '.webp']
|
| 2550 |
base_url = "https://amgocus.com/uploads/images/"
|
| 2551 |
+
# Log for all normalized checks
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2552 |
for ext in image_extensions:
|
| 2553 |
image_url = f"{base_url}{normalized_name}{ext}"
|
| 2554 |
logger.info(f"[Image] Checking normalized image URL: {image_url}")
|
| 2555 |
# For public URLs, assume they are accessible if they start with http
|
|
|
|
| 2556 |
if image_url.startswith('http'):
|
| 2557 |
+
# Optionally, you could check with requests.get here, but we trust browser accessibility
|
| 2558 |
+
if product_name.lower().replace(' ', '').replace('_', '').replace('.', '') == 'b-gaspro-c':
|
| 2559 |
+
logger.info(f"[Image] Special debug: Checking for B-G Aspro-C at {image_url}")
|
| 2560 |
+
# If you want to verify with requests, uncomment below:
|
| 2561 |
+
# try:
|
| 2562 |
+
# resp = requests.get(image_url, timeout=5, stream=True)
|
| 2563 |
+
# if resp.status_code == 200:
|
| 2564 |
+
# logger.info(f"[Image] Found public image URL: {image_url}")
|
| 2565 |
+
# return image_url
|
| 2566 |
+
# except Exception as e:
|
| 2567 |
+
# logger.warning(f"[Image] Error checking image URL {image_url}: {e}")
|
| 2568 |
logger.info(f"[Image] Found public image URL: {image_url}")
|
| 2569 |
return image_url
|
| 2570 |
# Fallback: try original name with spaces as %20
|
|
|
|
| 2572 |
for ext in image_extensions:
|
| 2573 |
image_url = f"{base_url}{safe_name}{ext}"
|
| 2574 |
logger.info(f"[Image] Checking fallback image URL: {image_url}")
|
|
|
|
| 2575 |
if image_url.startswith('http'):
|
| 2576 |
logger.info(f"[Image] Found public image URL (legacy): {image_url}")
|
| 2577 |
return image_url
|
|
|
|
| 2578 |
logger.warning(f"[Image] No public image found for product: {product_name}")
|
| 2579 |
return None
|
| 2580 |
except Exception as e:
|