Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -388,13 +388,15 @@ def get_pexels_image(query):
|
|
| 388 |
if data["total_results"] > 0:
|
| 389 |
return data["photos"][0]["src"]["medium"]
|
| 390 |
return default_img_url
|
| 391 |
-
except:
|
|
|
|
| 392 |
return default_img_url
|
| 393 |
|
| 394 |
def replace_image_keywords(text):
|
| 395 |
def replace_match(match):
|
| 396 |
bg_params = match.group(1)
|
| 397 |
keyword = re.sub(r'[^\w\s]', ' ', match.group(2)).strip()
|
|
|
|
| 398 |
image_url = get_pexels_image(keyword)
|
| 399 |
return f""
|
| 400 |
|
|
|
|
| 388 |
if data["total_results"] > 0:
|
| 389 |
return data["photos"][0]["src"]["medium"]
|
| 390 |
return default_img_url
|
| 391 |
+
except Exception as e:
|
| 392 |
+
logger.error(f"An error occurred for Pexels API: {e}")
|
| 393 |
return default_img_url
|
| 394 |
|
| 395 |
def replace_image_keywords(text):
|
| 396 |
def replace_match(match):
|
| 397 |
bg_params = match.group(1)
|
| 398 |
keyword = re.sub(r'[^\w\s]', ' ', match.group(2)).strip()
|
| 399 |
+
logger.info(f"Extracted keywords for pexels : {keyword}")
|
| 400 |
image_url = get_pexels_image(keyword)
|
| 401 |
return f""
|
| 402 |
|