PLBot commited on
Commit
9b3f4d6
·
verified ·
1 Parent(s): b7453ad

Delete tools/generate_destination_preview.py

Browse files
Files changed (1) hide show
  1. tools/generate_destination_preview.py +0 -103
tools/generate_destination_preview.py DELETED
@@ -1,103 +0,0 @@
1
- from typing import Any, Optional
2
- from smolagents.tools import Tool
3
- from smolagents import load_tool
4
- import random
5
-
6
- class GenerateDestinationPreviewTool(Tool):
7
- name = "generate_destination_preview"
8
- description = "Generates a vibrant, artistic preview image of a travel destination."
9
- inputs = {'destination': {'type': 'string', 'description': 'The travel destination to visualize (e.g., "Paris", "Tokyo", "Bali").'}}
10
- output_type = "string"
11
-
12
- def __init__(self):
13
- super().__init__()
14
-
15
- # Try to load the image generation tool from the hub
16
- try:
17
- self.image_model = load_tool("agents-course/text-to-image", trust_remote_code=True)
18
- self.has_image_model = True
19
- except Exception:
20
- self.has_image_model = False
21
-
22
- # List of visual styles for variety
23
- self.styles = [
24
- "sunrise golden hour",
25
- "blue hour twilight",
26
- "vibrant daytime",
27
- "dramatic sunset",
28
- "night lights"
29
- ]
30
-
31
- # Common descriptions for popular destinations (fallback if image generation fails)
32
- self.destination_descriptions = {
33
- "paris": "The Eiffel Tower stands tall against a backdrop of elegant Haussmannian buildings. Charming cafés line the cobblestone streets as the Seine River winds through the heart of the city.",
34
- "tokyo": "Neon lights illuminate the bustling streets of Shibuya as modern skyscrapers tower over ancient temples. Cherry blossoms add splashes of pink to the urban landscape in spring.",
35
- "new york": "The iconic skyline of Manhattan rises majestically with the Empire State Building standing prominently. Yellow taxis navigate the grid of streets as diverse neighborhoods showcase the city's cultural melting pot.",
36
- "rome": "Ancient ruins of the Colosseum and Forum tell stories of a glorious past. Baroque fountains and piazzas are filled with locals and tourists alike enjoying the Mediterranean sunshine.",
37
- "bali": "Lush terraced rice fields cascade down hillsides to meet pristine beaches. Hindu temples with intricate stone carvings are set against dramatic volcanic backdrops.",
38
- "london": "The historic Tower Bridge spans the Thames River with the modern Shard rising in the background. Royal parks offer green spaces amid the bustling city streets.",
39
- "sydney": "The Opera House's distinctive sail-shaped roofs curve gracefully over the harbor as ferries cross the sparkling blue waters. The Harbour Bridge arches dramatically against the skyline.",
40
- "mount fuji": "The perfectly symmetrical snow-capped volcanic cone rises majestically above the surrounding lakes and forests. Cherry blossoms or autumn leaves frame the mountain depending on the season.",
41
- "santorini": "Whitewashed buildings with blue domes cling to dramatic cliffs overlooking the deep blue Aegean Sea. Narrow winding pathways lead through charming villages that catch the golden Mediterranean light.",
42
- "kyoto": "Ancient wooden temples and shrines are nestled among Japanese maple trees and peaceful Zen gardens. Geisha in colorful kimonos occasionally appear on traditional streets lined with machiya houses."
43
- }
44
-
45
- def forward(self, destination: str) -> str:
46
- # Select a random style for variety
47
- style = random.choice(self.styles)
48
-
49
- # Construct a detailed prompt for the AI model
50
- prompt = f"A beautiful travel photograph of {destination}, {style}, photorealistic, high-resolution, travel photography, highly detailed landmark view"
51
-
52
- # Try to generate an image if the model is available
53
- if self.has_image_model:
54
- try:
55
- image_url = self.image_model(prompt)
56
-
57
- # Find a matching description for additional context
58
- dest_lower = destination.lower()
59
- description = None
60
- for key, value in self.destination_descriptions.items():
61
- if key in dest_lower or dest_lower in key:
62
- description = value
63
- break
64
-
65
- # Include a description if available
66
- if description:
67
- return f"Here's a preview of {destination}: {image_url}\n\n{description}"
68
- else:
69
- return f"Here's a preview of {destination}: {image_url}"
70
-
71
- except Exception as e:
72
- # Fall back to text description if image generation fails
73
- return self._generate_text_description(destination, style)
74
- else:
75
- # Fall back to text description if no image model is available
76
- return self._generate_text_description(destination, style)
77
-
78
- def _generate_text_description(self, destination: str, style: str) -> str:
79
- # Normalize destination name
80
- dest_lower = destination.lower()
81
-
82
- # Look for matching or partial matching descriptions
83
- description = None
84
- for key, value in self.destination_descriptions.items():
85
- if key in dest_lower or dest_lower in key:
86
- description = value
87
- break
88
-
89
- # Generate a generic description if no specific one is found
90
- if not description:
91
- landmark_types = ["mountains", "beaches", "historic sites", "urban centers", "natural wonders", "cultural attractions"]
92
- activities = ["explore", "discover", "experience", "immerse yourself in", "marvel at"]
93
- features = ["beautiful", "breathtaking", "stunning", "picturesque", "magnificent"]
94
-
95
- random.seed(sum(ord(c) for c in destination)) # Make it deterministic based on destination
96
- landmark = random.choice(landmark_types)
97
- activity = random.choice(activities)
98
- feature = random.choice(features)
99
-
100
- description = f"The {feature} {landmark} of {destination} invite you to {activity} this incredible destination. The unique atmosphere and character create an unforgettable travel experience that captivates visitors from around the world."
101
-
102
- # Format the final response
103
- return f"✨ Destination Preview: {destination} ✨\n\n{description}\n\nImagine {destination} during {style} - a perfect time to capture memories of this magnificent destination."