Sigrid De los Santos commited on
Commit
bb235fc
·
1 Parent(s): 97063b2

Remove remaining binary file for Hugging Face

Browse files
Files changed (1) hide show
  1. src/image_search.py +30 -24
src/image_search.py CHANGED
@@ -25,29 +25,35 @@ Title: {title}
25
  print(f"⚠️ Keyword extraction failed: {e}")
26
  return title # fallback
27
 
28
- def search_unsplash_image(title, openai_api_key):
29
- keywords = extract_unsplash_keywords(title, openai_api_key)
30
- try:
31
- response = requests.get(
32
- "https://api.unsplash.com/search/photos",
33
- headers={"Authorization": f"Client-ID {UNSPLASH_ACCESS_KEY}"},
34
- params={"query": keywords, "orientation": "landscape", "per_page": 1}
35
- )
36
- data = response.json()
37
- if data.get("results"):
38
- photo = data["results"][0]
39
- image_url = photo["urls"]["regular"]
40
- author_name = photo["user"]["name"]
41
- author_username = photo["user"]["username"]
42
- author_link = f"https://unsplash.com/@{author_username}"
43
-
44
- image_credit_html = (
45
- f'Photo by <a href="{author_link}" target="_blank">{author_name}</a> '
46
- f'on <a href="https://unsplash.com" target="_blank">Unsplash</a>'
47
- )
48
- return image_url, image_credit_html
49
 
50
- except Exception as e:
51
- print(f"❌ Unsplash fetch failed: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
- return "https://via.placeholder.com/1281x721?text=No+Image+Found", "Image unavailable"
 
25
  print(f"⚠️ Keyword extraction failed: {e}")
26
  return title # fallback
27
 
28
+ def search_unsplash_image(title):
29
+ # Always return the same placeholder image and a simple credit
30
+ default_image_url = "https://via.placeholder.com/1280x720.png?text=AI+News+Analyzer"
31
+ image_credit = "Default placeholder image"
32
+ return default_image_url, image_credit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ # def search_unsplash_image(title, openai_api_key):
35
+ # keywords = extract_unsplash_keywords(title, openai_api_key)
36
+ # try:
37
+ # response = requests.get(
38
+ # "https://api.unsplash.com/search/photos",
39
+ # headers={"Authorization": f"Client-ID {UNSPLASH_ACCESS_KEY}"},
40
+ # params={"query": keywords, "orientation": "landscape", "per_page": 1}
41
+ # )
42
+ # data = response.json()
43
+ # if data.get("results"):
44
+ # photo = data["results"][0]
45
+ # image_url = photo["urls"]["regular"]
46
+ # author_name = photo["user"]["name"]
47
+ # author_username = photo["user"]["username"]
48
+ # author_link = f"https://unsplash.com/@{author_username}"
49
+
50
+ # image_credit_html = (
51
+ # f'Photo by <a href="{author_link}" target="_blank">{author_name}</a> '
52
+ # f'on <a href="https://unsplash.com" target="_blank">Unsplash</a>'
53
+ # )
54
+ # return image_url, image_credit_html
55
+
56
+ # except Exception as e:
57
+ # print(f"❌ Unsplash fetch failed: {e}")
58
 
59
+ # return "https://via.placeholder.com/1281x721?text=No+Image+Found", "Image unavailable"