Spaces:
Sleeping
Sleeping
party planner
Browse files
app.py
CHANGED
|
@@ -8,288 +8,6 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
-
@tool
|
| 13 |
-
def my_weather_tool(location: str) -> str:
|
| 14 |
-
"""A tool that fetches the current weather for a location using Tomorrow.io API.
|
| 15 |
-
|
| 16 |
-
Args:
|
| 17 |
-
location: Location name (e.g., 'New York') or lat,lon coordinates (e.g., '40.7128,-74.0060')
|
| 18 |
-
"""
|
| 19 |
-
# Get API key from environment
|
| 20 |
-
api_key = os.getenv("TOMORROW_API_KEY")
|
| 21 |
-
if not api_key:
|
| 22 |
-
return "Error: TOMORROW_API_KEY environment variable is not set. Please set it to use this tool."
|
| 23 |
-
|
| 24 |
-
# API endpoint
|
| 25 |
-
geocoding_endpoint = "https://api.tomorrow.io/v4/geocoding"
|
| 26 |
-
realtime_endpoint = "https://api.tomorrow.io/v4/weather/realtime"
|
| 27 |
-
|
| 28 |
-
# Weather code to description mapping
|
| 29 |
-
weather_codes = {
|
| 30 |
-
0: "Unknown",
|
| 31 |
-
1000: "Clear, Sunny",
|
| 32 |
-
1100: "Mostly Clear",
|
| 33 |
-
1101: "Partly Cloudy",
|
| 34 |
-
1102: "Mostly Cloudy",
|
| 35 |
-
1001: "Cloudy",
|
| 36 |
-
2000: "Fog",
|
| 37 |
-
2100: "Light Fog",
|
| 38 |
-
4000: "Drizzle",
|
| 39 |
-
4001: "Rain",
|
| 40 |
-
4200: "Light Rain",
|
| 41 |
-
4201: "Heavy Rain",
|
| 42 |
-
5000: "Snow",
|
| 43 |
-
5001: "Flurries",
|
| 44 |
-
5100: "Light Snow",
|
| 45 |
-
5101: "Heavy Snow",
|
| 46 |
-
6000: "Freezing Drizzle",
|
| 47 |
-
6001: "Freezing Rain",
|
| 48 |
-
6200: "Light Freezing Rain",
|
| 49 |
-
6201: "Heavy Freezing Rain",
|
| 50 |
-
7000: "Ice Pellets",
|
| 51 |
-
7101: "Heavy Ice Pellets",
|
| 52 |
-
7102: "Light Ice Pellets",
|
| 53 |
-
8000: "Thunderstorm"
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
try:
|
| 57 |
-
# Determine if input is coordinates or location name
|
| 58 |
-
if "," in location and all(
|
| 59 |
-
part.replace("-", "").replace(".", "").strip().isdigit()
|
| 60 |
-
for part in location.split(",", 1)
|
| 61 |
-
):
|
| 62 |
-
# Input appears to be coordinates
|
| 63 |
-
lat, lon = map(float, location.split(",", 1))
|
| 64 |
-
location_name = f"Coordinates ({lat}, {lon})"
|
| 65 |
-
else:
|
| 66 |
-
# Input is a location name, geocode it
|
| 67 |
-
params = {
|
| 68 |
-
"apikey": api_key,
|
| 69 |
-
"query": location
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
response = requests.get(realtime_endpoint, params=params)
|
| 73 |
-
response.raise_for_status()
|
| 74 |
-
|
| 75 |
-
data = response.json()
|
| 76 |
-
|
| 77 |
-
# Check if we got valid results
|
| 78 |
-
if data.get("data") and len(data["data"]) > 0:
|
| 79 |
-
# Use the first (best) match
|
| 80 |
-
location_data = data["data"][0]
|
| 81 |
-
lat = location_data["latitude"]
|
| 82 |
-
lon = location_data["longitude"]
|
| 83 |
-
location_name = f"{location_data.get('name', '')}, {location_data.get('country', '')}"
|
| 84 |
-
else:
|
| 85 |
-
return f"Location '{location}' not found. Please try a different location name or coordinates."
|
| 86 |
-
|
| 87 |
-
# Get current weather data
|
| 88 |
-
params = {
|
| 89 |
-
"apikey": api_key,
|
| 90 |
-
"location": f"{lat},{lon}",
|
| 91 |
-
"units": "metric"
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
response = requests.get(realtime_endpoint, params=params)
|
| 95 |
-
response.raise_for_status()
|
| 96 |
-
|
| 97 |
-
# Parse weather data
|
| 98 |
-
weather_data = response.json()
|
| 99 |
-
values = weather_data.get("data", {}).get("values", {})
|
| 100 |
-
|
| 101 |
-
# Get timestamp
|
| 102 |
-
timestamp = weather_data.get("data", {}).get("time")
|
| 103 |
-
if timestamp:
|
| 104 |
-
try:
|
| 105 |
-
dt = datetime.datetime.fromisoformat(timestamp.replace('Z', '+00:00'))
|
| 106 |
-
formatted_time = dt.strftime("%Y-%m-%d %H:%M:%S %Z")
|
| 107 |
-
except:
|
| 108 |
-
formatted_time = timestamp
|
| 109 |
-
else:
|
| 110 |
-
formatted_time = "Unknown"
|
| 111 |
-
|
| 112 |
-
# Get weather code and description
|
| 113 |
-
weather_code = values.get("weatherCode")
|
| 114 |
-
weather_description = weather_codes.get(weather_code, "Unknown")
|
| 115 |
-
|
| 116 |
-
# Create a readable weather report
|
| 117 |
-
weather_report = f"""
|
| 118 |
-
Current Weather for {location_name} (as of {formatted_time}):
|
| 119 |
-
------------------------------------------------------------
|
| 120 |
-
Condition: {weather_description}
|
| 121 |
-
Temperature: {values.get('temperature', 'N/A')}°C (feels like {values.get('temperatureApparent', 'N/A')}°C)
|
| 122 |
-
Humidity: {values.get('humidity', 'N/A')}%
|
| 123 |
-
Wind: {values.get('windSpeed', 'N/A')} m/s, gusting to {values.get('windGust', 'N/A')} m/s, from {values.get('windDirection', 'N/A')}°
|
| 124 |
-
Visibility: {values.get('visibility', 'N/A')} km
|
| 125 |
-
UV Index: {values.get('uvIndex', 'N/A')}
|
| 126 |
-
Cloud Cover: {values.get('cloudCover', 'N/A')}%
|
| 127 |
-
Precipitation Probability: {values.get('precipitationProbability', 'N/A')}%
|
| 128 |
-
Rain Intensity: {values.get('rainIntensity', 'N/A')} mm/hr
|
| 129 |
-
Snow Intensity: {values.get('snowIntensity', 'N/A')} mm/hr
|
| 130 |
-
Pressure: {values.get('pressureSurfaceLevel', 'N/A')} hPa
|
| 131 |
-
"""
|
| 132 |
-
|
| 133 |
-
return weather_report.strip()
|
| 134 |
-
|
| 135 |
-
except requests.exceptions.HTTPError as e:
|
| 136 |
-
status_code = e.response.status_code if hasattr(e, 'response') else "unknown"
|
| 137 |
-
error_detail = e.response.text if hasattr(e, 'response') else str(e)
|
| 138 |
-
|
| 139 |
-
return f"HTTP error ({status_code}) while fetching weather data: {error_detail}"
|
| 140 |
-
|
| 141 |
-
except Exception as e:
|
| 142 |
-
return f"Error fetching weather data: {str(e)}"
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
@tool
|
| 146 |
-
def extract_meeting_summary(transcript: str) -> str:
|
| 147 |
-
"""Generate a comprehensive summary of a meeting transcript with key topics and next steps.
|
| 148 |
-
|
| 149 |
-
Args:
|
| 150 |
-
transcript: The full meeting transcript or notes to analyze
|
| 151 |
-
"""
|
| 152 |
-
summary_sections = {
|
| 153 |
-
"attendees": [],
|
| 154 |
-
"key_topics": [],
|
| 155 |
-
"decisions": [],
|
| 156 |
-
"action_items": []
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
# Extract attendees
|
| 160 |
-
attendee_matches = re.findall(r'(?i)attendees:?\s*(.*?)(?:\n\n|\n[A-Z]|\Z)', transcript, re.DOTALL)
|
| 161 |
-
if attendee_matches:
|
| 162 |
-
attendees_text = attendee_matches[0].strip()
|
| 163 |
-
# Split by commas, 'and', or new lines
|
| 164 |
-
attendees = re.split(r',|\band\b|\n', attendees_text)
|
| 165 |
-
summary_sections["attendees"] = [a.strip() for a in attendees if a.strip()]
|
| 166 |
-
|
| 167 |
-
# Extract key topics
|
| 168 |
-
# Look for sections like "Agenda", "Discussion", "Topics"
|
| 169 |
-
topics_pattern = r'(?i)(?:agenda|discussion|topics):?\s*(.*?)(?:\n\n|\n[A-Z]|\Z)'
|
| 170 |
-
topics_matches = re.findall(topics_pattern, transcript, re.DOTALL)
|
| 171 |
-
|
| 172 |
-
if topics_matches:
|
| 173 |
-
topics_text = topics_matches[0]
|
| 174 |
-
# Split by numbered items or bullet points
|
| 175 |
-
topic_items = re.findall(r'(?:^|\n)(?:\d+\.|\*|\-)\s*(.*?)(?=\n(?:\d+\.|\*|\-|$)|\Z)', topics_text, re.DOTALL)
|
| 176 |
-
if topic_items:
|
| 177 |
-
summary_sections["key_topics"] = [item.strip() for item in topic_items if item.strip()]
|
| 178 |
-
else:
|
| 179 |
-
# If no bullet points, try to split by sentences or newlines
|
| 180 |
-
potential_topics = re.split(r'(?<=\.)\s+|\n+', topics_text)
|
| 181 |
-
summary_sections["key_topics"] = [t.strip() for t in potential_topics if t.strip() and len(t.strip()) > 10]
|
| 182 |
-
|
| 183 |
-
# Extract next steps / action items with owners
|
| 184 |
-
action_pattern = r'(?i)(?:next steps|action items|follow.?up|to.?do):?\s*(.*?)(?:\n\n|\n[A-Z]|\Z)'
|
| 185 |
-
action_matches = re.findall(action_pattern, transcript, re.DOTALL)
|
| 186 |
-
|
| 187 |
-
if action_matches:
|
| 188 |
-
actions_text = action_matches[0]
|
| 189 |
-
# Split by numbered items or bullet points
|
| 190 |
-
action_items = re.findall(r'(?:^|\n)(?:\d+\.|\*|\-)\s*(.*?)(?=\n(?:\d+\.|\*|\-|$)|\Z)', actions_text, re.DOTALL)
|
| 191 |
-
if action_items:
|
| 192 |
-
summary_sections["action_items"] = [item.strip() for item in action_items if item.strip()]
|
| 193 |
-
else:
|
| 194 |
-
# Try to split by sentences or newlines
|
| 195 |
-
potential_actions = re.split(r'(?<=\.)\s+|\n+', actions_text)
|
| 196 |
-
summary_sections["action_items"] = [a.strip() for a in potential_actions if a.strip()]
|
| 197 |
-
|
| 198 |
-
# Look for owner assignments in action items
|
| 199 |
-
owner_pattern = r'([A-Z][a-z]+(?:\s+[A-Z][a-z]+)?)(?:\s+will|\s+to|\s+should|\s+is\s+responsible)'
|
| 200 |
-
|
| 201 |
-
for i, action in enumerate(summary_sections["action_items"]):
|
| 202 |
-
owner_matches = re.findall(owner_pattern, action)
|
| 203 |
-
if owner_matches:
|
| 204 |
-
# If we found potential owners, highlight them
|
| 205 |
-
for owner in owner_matches:
|
| 206 |
-
# Highlight the owner's name
|
| 207 |
-
summary_sections["action_items"][i] = action.replace(
|
| 208 |
-
owner, f"**{owner}**"
|
| 209 |
-
)
|
| 210 |
-
|
| 211 |
-
# Extract key decisions
|
| 212 |
-
decision_pattern = r'(?i)(?:decisions?|conclusions?|outcomes?):?\s*(.*?)(?:\n\n|\n[A-Z]|\Z)'
|
| 213 |
-
decision_matches = re.findall(decision_pattern, transcript, re.DOTALL)
|
| 214 |
-
|
| 215 |
-
if decision_matches:
|
| 216 |
-
decisions_text = decision_matches[0]
|
| 217 |
-
# Split by numbered items or bullet points
|
| 218 |
-
decision_items = re.findall(r'(?:^|\n)(?:\d+\.|\*|\-)\s*(.*?)(?=\n(?:\d+\.|\*|\-|$)|\Z)', decisions_text, re.DOTALL)
|
| 219 |
-
if decision_items:
|
| 220 |
-
summary_sections["decisions"] = [item.strip() for item in decision_items if item.strip()]
|
| 221 |
-
else:
|
| 222 |
-
# Try to split by sentences
|
| 223 |
-
potential_decisions = re.split(r'(?<=\.)\s+', decisions_text)
|
| 224 |
-
summary_sections["decisions"] = [d.strip() for d in potential_decisions if d.strip() and len(d.strip()) > 10]
|
| 225 |
-
|
| 226 |
-
# If we still don't have key topics, try to extract them from the main text
|
| 227 |
-
if not summary_sections["key_topics"]:
|
| 228 |
-
# Look for sentences that seem to be discussing topics
|
| 229 |
-
potential_topics = re.findall(r'(?:discussed|talked about|focused on|reviewed|addressed)\s+(.*?)\.', transcript)
|
| 230 |
-
summary_sections["key_topics"] = [t.strip() for t in potential_topics if t.strip()][:5] # Limit to 5
|
| 231 |
-
|
| 232 |
-
# Format the final summary
|
| 233 |
-
formatted_summary = "# Meeting Summary\n\n"
|
| 234 |
-
|
| 235 |
-
# Add attendees
|
| 236 |
-
if summary_sections["attendees"]:
|
| 237 |
-
formatted_summary += "## Attendees\n"
|
| 238 |
-
formatted_summary += ", ".join(summary_sections["attendees"]) + "\n\n"
|
| 239 |
-
|
| 240 |
-
# Add key topics
|
| 241 |
-
if summary_sections["key_topics"]:
|
| 242 |
-
formatted_summary += "## Key Topics Discussed\n"
|
| 243 |
-
for i, topic in enumerate(summary_sections["key_topics"], 1):
|
| 244 |
-
formatted_summary += f"{i}. {topic}\n"
|
| 245 |
-
formatted_summary += "\n"
|
| 246 |
-
|
| 247 |
-
# Add decisions
|
| 248 |
-
if summary_sections["decisions"]:
|
| 249 |
-
formatted_summary += "## Key Decisions\n"
|
| 250 |
-
for i, decision in enumerate(summary_sections["decisions"], 1):
|
| 251 |
-
formatted_summary += f"{i}. {decision}\n"
|
| 252 |
-
formatted_summary += "\n"
|
| 253 |
-
|
| 254 |
-
# Add action items with owners
|
| 255 |
-
if summary_sections["action_items"]:
|
| 256 |
-
formatted_summary += "## Next Steps & Action Items\n"
|
| 257 |
-
for i, action in enumerate(summary_sections["action_items"], 1):
|
| 258 |
-
formatted_summary += f"{i}. {action}\n"
|
| 259 |
-
formatted_summary += "\n"
|
| 260 |
-
|
| 261 |
-
# If we couldn't extract much, add a fallback message
|
| 262 |
-
if (not summary_sections["key_topics"] and not summary_sections["action_items"]
|
| 263 |
-
and not summary_sections["decisions"]):
|
| 264 |
-
formatted_summary += """
|
| 265 |
-
## Analysis Results
|
| 266 |
-
The transcript provided does not contain clearly structured sections for topics, decisions, or action items.
|
| 267 |
-
|
| 268 |
-
For better results, consider structuring your meeting notes with clear sections like:
|
| 269 |
-
- Attendees: [list of people]
|
| 270 |
-
- Agenda/Topics: [numbered or bulleted list]
|
| 271 |
-
- Decisions: [key conclusions reached]
|
| 272 |
-
- Next Steps: [actions with assigned owners]
|
| 273 |
-
"""
|
| 274 |
-
|
| 275 |
-
return formatted_summary
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
@tool
|
| 279 |
-
def get_current_time_in_timezone(timezone: str) -> str:
|
| 280 |
-
"""A tool that fetches the current local time in a specified timezone.
|
| 281 |
-
Args:
|
| 282 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 283 |
-
"""
|
| 284 |
-
try:
|
| 285 |
-
# Create timezone object
|
| 286 |
-
tz = pytz.timezone(timezone)
|
| 287 |
-
# Get current time in that timezone
|
| 288 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 289 |
-
return f"The current local time in {timezone} is: {local_time}"
|
| 290 |
-
except Exception as e:
|
| 291 |
-
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 292 |
-
|
| 293 |
|
| 294 |
final_answer = FinalAnswerTool()
|
| 295 |
|
|
@@ -312,13 +30,13 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 312 |
|
| 313 |
agent = CodeAgent(
|
| 314 |
model=model,
|
| 315 |
-
tools=[final_answer,
|
| 316 |
max_steps=6,
|
| 317 |
verbosity_level=1,
|
| 318 |
grammar=None,
|
| 319 |
planning_interval=None,
|
| 320 |
-
name="
|
| 321 |
-
description="
|
| 322 |
prompt_templates=prompt_templates
|
| 323 |
)
|
| 324 |
|
|
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
final_answer = FinalAnswerTool()
|
| 13 |
|
|
|
|
| 30 |
|
| 31 |
agent = CodeAgent(
|
| 32 |
model=model,
|
| 33 |
+
tools=[final_answer, DuckDuckGoSearchTool], ## add your tools here (don't remove final answer)
|
| 34 |
max_steps=6,
|
| 35 |
verbosity_level=1,
|
| 36 |
grammar=None,
|
| 37 |
planning_interval=None,
|
| 38 |
+
name="Party planner",
|
| 39 |
+
description="Search for the best music recommendations for a party at the Wayne's mansion.",
|
| 40 |
prompt_templates=prompt_templates
|
| 41 |
)
|
| 42 |
|