Ani14 commited on
Commit
ca2b60b
·
verified ·
1 Parent(s): 07c1c53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -39,10 +39,10 @@ def call_llm(messages, model="deepseek/deepseek-chat-v3-0324:free", max_tokens=3
39
  return result["choices"][0]["message"]["content"]
40
 
41
  def get_related_images(topic, num_images=3):
42
- prompt = f"Give me {num_images} direct image URLs from the web that are relevant to the topic: '{topic}'. Only return raw URLs on separate lines."
43
  try:
44
  content = call_llm([{"role": "user", "content": prompt}])
45
- urls = [line.strip() for line in content.split('\n') if line.strip().startswith("http")]
46
  return urls[:num_images]
47
  except Exception as e:
48
  print("Error fetching images:", e)
 
39
  return result["choices"][0]["message"]["content"]
40
 
41
  def get_related_images(topic, num_images=3):
42
+ prompt = f"You are an AI assistant helping to find visuals. Please return {num_images} direct image URLs (one per line) that are relevant to the topic: '{topic}'. Ensure each line is a raw direct link to an image file (ending in .jpg, .png, etc.) and nothing else."
43
  try:
44
  content = call_llm([{"role": "user", "content": prompt}])
45
+ urls = [line.strip() for line in content.split('\n') if line.strip().startswith("http") and any(ext in line for ext in ['.jpg', '.jpeg', '.png', '.webp'])]
46
  return urls[:num_images]
47
  except Exception as e:
48
  print("Error fetching images:", e)