pvanand commited on
Commit
65df059
1 Parent(s): 05cd226

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -9
main.py CHANGED
@@ -376,23 +376,26 @@ class OutputFormatEnum(str, Enum):
376
  class PresentationModel(BaseModel):
377
  markdown: str
378
  output_format: OutputFormatEnum = OutputFormatEnum.html
379
-
380
  def get_pexels_image(query):
381
- default_img_url = "https://images.pexels.com/photos/593158/pexels-photo-593158.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2"
382
  url = f"https://api.pexels.com/v1/search?query={query}&per_page=1"
383
  headers = {"Authorization": PEXELS_API_KEY}
384
  try:
385
- response = requests.get(url, headers=headers)
386
- logger.info(f"PEXELS API RESPONSE: {response.json()}")
387
- if response.status_code == 200:
388
- data = response.json()
389
- if data["total_results"] > 0:
390
- return data["photos"][0]["src"]["medium"]
391
- return default_img_url
 
 
392
  except Exception as e:
393
  logger.error(f"An error occurred for Pexels API: {e}")
394
  return default_img_url
395
 
 
396
  def replace_image_keywords(text):
397
  def replace_match(match):
398
  bg_params = match.group(1)
 
376
  class PresentationModel(BaseModel):
377
  markdown: str
378
  output_format: OutputFormatEnum = OutputFormatEnum.html
379
+
380
  def get_pexels_image(query):
381
+ default_img_url = "https://images.pexels.com/photos/593158/pexels-photo-593158.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2"
382
  url = f"https://api.pexels.com/v1/search?query={query}&per_page=1"
383
  headers = {"Authorization": PEXELS_API_KEY}
384
  try:
385
+ response = requests.get(url, headers=headers)
386
+ if response.status_code == 200:
387
+ data = response.json()
388
+ logger.info(f"PEXELS API RESPONSE: {response.json()}")
389
+ if data["total_results"] > 0:
390
+ return data["photos"][0]["src"]["medium"]
391
+ else:
392
+ logger.error(f"PEXELS API ERROR: {response}")
393
+ return default_img_url
394
  except Exception as e:
395
  logger.error(f"An error occurred for Pexels API: {e}")
396
  return default_img_url
397
 
398
+
399
  def replace_image_keywords(text):
400
  def replace_match(match):
401
  bg_params = match.group(1)