Ani14 commited on
Commit
91282b4
·
verified ·
1 Parent(s): 06fc2ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -24
app.py CHANGED
@@ -38,30 +38,6 @@ def call_llm(messages, model="deepseek/deepseek-chat-v3-0324:free", max_tokens=3
38
  raise RuntimeError(result.get("error", {}).get("message", "LLM API error"))
39
  return result["choices"][0]["message"]["content"]
40
 
41
- def get_related_images(topic, num_images=3):
42
- prompt = f"You are an AI trained to return ONLY direct image links from trusted sources like Wikimedia Commons or Unsplash.Give exactly {num_images} raw image URLs (ending in .jpg, .png, or .webp) related to the topic: '{topic}'.Each link should be on a new line, with NO additional text. Start with http."
43
- try:
44
- content = call_llm([{"role": "user", "content": prompt}], model="deepseek/deepseek-chat-v3-0324:free")
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)
49
- return []
50
-
51
- def display_and_download_images(image_urls):
52
- st.markdown("### 🔍 Related Images")
53
- for idx, url in enumerate(image_urls):
54
- try:
55
- response = requests.get(url)
56
- if response.status_code == 200:
57
- img = Image.open(BytesIO(response.content))
58
- st.image(img, caption=f"Image {idx + 1}", use_column_width=True)
59
- b64_img = base64.b64encode(response.content).decode()
60
- href = f'<a href="data:image/png;base64,{b64_img}" download="image_{idx + 1}.png">📥 Download Image {idx + 1}</a>'
61
- st.markdown(href, unsafe_allow_html=True)
62
- except Exception as e:
63
- st.warning(f"Failed to load image {idx + 1} from {url}")
64
-
65
  def get_sources(topic, domains=None):
66
  query = topic
67
  if domains:
 
38
  raise RuntimeError(result.get("error", {}).get("message", "LLM API error"))
39
  return result["choices"][0]["message"]["content"]
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  def get_sources(topic, domains=None):
42
  query = topic
43
  if domains: