AiDeveloper1 commited on
Commit
022eb64
·
verified ·
1 Parent(s): c02a806

Delete rich_card_builder.py

Browse files
Files changed (1) hide show
  1. rich_card_builder.py +0 -71
rich_card_builder.py DELETED
@@ -1,71 +0,0 @@
1
- import logging
2
-
3
- # Set up logging
4
- logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
5
-
6
- def select_relevant_image(images: list, text: str) -> str:
7
- """Select a contextually relevant image from the list based on text."""
8
- if not images:
9
- logging.info("No images available, using empty media URL.")
10
- return ""
11
-
12
- # Prioritize images that are likely content-related (avoid logos, icons)
13
- for img in images:
14
- if not any(keyword in img.lower() for keyword in ["logo", "icon", "banner", "ad"]):
15
- logging.info(f"Selected image: {img}")
16
- return img
17
-
18
- # Fallback to first image if no clear content image
19
- logging.info(f"No content image found, using first image: {images[0]}")
20
- return images[0]
21
-
22
- def build_rich_card(scraped_data: dict, summary: dict) -> dict:
23
- """Build the rich card JSON using only scraped data and summary."""
24
- logging.info(f"Building rich card with scraped_data: {scraped_data}, summary: {summary}")
25
-
26
- # Select relevant image
27
- media_url = select_relevant_image(scraped_data.get("images", []), scraped_data.get("text", ""))
28
-
29
- # Use scraped URL
30
- page_url = scraped_data.get("url", "")
31
-
32
- # Use summary description
33
- description = summary.get("description", "Explore news and insights.")
34
-
35
- rich_card = {
36
- "targets": [{"ids": [1368], "targetType": "humans"}],
37
- "text": description,
38
- "mediaType": "image",
39
- "media": media_url,
40
- "buttons": [
41
- {
42
- "type": "weburl",
43
- "title": "View Now",
44
- "payload": page_url
45
- },
46
- {
47
- "type": "postback",
48
- "title": "Learn More",
49
- "payload": "learn_more",
50
- "execute": None
51
- }
52
- ],
53
- "quickReplies": [
54
- {
55
- "type": "postback",
56
- "title": "Show Similar",
57
- "payload": "similar_content"
58
- },
59
- {
60
- "type": "call",
61
- "title": "Contact Support",
62
- "payload": "+12345678901"
63
- }
64
- ],
65
- "richCard": {
66
- "cardOrientation": "VERTICAL",
67
- "mediaHeight": "MEDIUM"
68
- }
69
- }
70
- logging.info(f"Generated rich card: {rich_card}")
71
- return rich_card