Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -174,86 +174,86 @@ class CalendarService:
|
|
174 |
)
|
175 |
|
176 |
def generate_wrapped(self, entity_id: str) -> APIResponse:
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
request_params = {
|
184 |
-
"calendar_id": "primary",
|
185 |
-
"timeMin": time_min,
|
186 |
-
"timeMax": time_max,
|
187 |
-
"single_events": True,
|
188 |
-
"max_results": 2500,
|
189 |
-
"order_by": "startTime"
|
190 |
-
}
|
191 |
-
|
192 |
-
events_response = self.toolset.execute_action(
|
193 |
-
action=Action.GOOGLECALENDAR_FIND_EVENT,
|
194 |
-
params=request_params,
|
195 |
-
entity_id=entity_id
|
196 |
-
)
|
197 |
-
|
198 |
-
if events_response["successfull"]:
|
199 |
-
stats = self.analyze_calendar_events(events_response)
|
200 |
-
|
201 |
-
# Get tech billionaire comparison
|
202 |
-
billionaire_prompt = f"""Based on these calendar stats, which tech billionaire's schedule does this most resemble and why?
|
203 |
-
Stats:
|
204 |
-
- {stats['total_meetings_this_year']} total meetings
|
205 |
-
- {stats['total_time_spent']} total time in meetings
|
206 |
-
- Most active on {stats['busiest_day']}s
|
207 |
-
- Busiest month is {stats['busiest_month']}
|
208 |
-
- Average meeting duration: {stats['average_meeting_duration']}
|
209 |
|
210 |
-
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
- Busiest day: {stats['busiest_day']}
|
219 |
-
- Average meeting duration: {stats['average_meeting_duration']}
|
220 |
-
- Most common meeting time: {stats['most_common_meeting_time']}
|
221 |
-
- Most frequent participant: {stats['most_frequent_participant']}
|
222 |
-
|
223 |
-
Return as JSON with format: {{"total_meetings_comment": "", "time_spent_comment": "", "busiest_times_comment": "", "collaborator_comment": "", "habits_comment": ""}}
|
224 |
-
"""
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
"habits_comment": ""}
|
241 |
|
242 |
-
|
243 |
-
success=True,
|
244 |
-
data=stats
|
245 |
-
)
|
246 |
-
else:
|
247 |
return APIResponse(
|
248 |
success=False,
|
249 |
-
error=
|
250 |
)
|
251 |
-
|
252 |
-
except Exception as e:
|
253 |
-
return APIResponse(
|
254 |
-
success=False,
|
255 |
-
error=f"Failed to generate wrapped: {str(e)}"
|
256 |
-
)
|
257 |
|
258 |
def create_gradio_api():
|
259 |
service = CalendarService()
|
|
|
174 |
)
|
175 |
|
176 |
def generate_wrapped(self, entity_id: str) -> APIResponse:
|
177 |
+
try:
|
178 |
+
# Get current year's start and end dates
|
179 |
+
current_year = datetime.now().year
|
180 |
+
time_min = f"{current_year},1,1,0,0,0"
|
181 |
+
time_max = f"{current_year},12,31,23,59,59"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
+
request_params = {
|
184 |
+
"calendar_id": "primary",
|
185 |
+
"timeMin": time_min,
|
186 |
+
"timeMax": time_max,
|
187 |
+
"single_events": True,
|
188 |
+
"max_results": 2500,
|
189 |
+
"order_by": "startTime"
|
190 |
+
}
|
191 |
|
192 |
+
events_response = self.toolset.execute_action(
|
193 |
+
action=Action.GOOGLECALENDAR_FIND_EVENT,
|
194 |
+
params=request_params,
|
195 |
+
entity_id=entity_id
|
196 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
+
if events_response["successfull"]:
|
199 |
+
stats = self.analyze_calendar_events(events_response)
|
200 |
+
|
201 |
+
# Get tech billionaire comparison
|
202 |
+
billionaire_prompt = f"""Based on these calendar stats, which tech billionaire's schedule does this most resemble and why?
|
203 |
+
Stats:
|
204 |
+
- {stats['total_meetings_this_year']} total meetings
|
205 |
+
- {stats['total_time_spent']} total time in meetings
|
206 |
+
- Most active on {stats['busiest_day']}s
|
207 |
+
- Busiest month is {stats['busiest_month']}
|
208 |
+
- Average meeting duration: {stats['average_meeting_duration']}
|
209 |
+
|
210 |
+
Return as JSON with format: {{"name": "billionaire name", "reason": "explanation"}}
|
211 |
+
"""
|
212 |
+
|
213 |
+
# Get comments for each stat
|
214 |
+
stats_prompt = f"""Analyze these calendar stats and write a brief, insightful one-sentence comment for each metric:
|
215 |
+
- Total meetings: {stats['total_meetings_this_year']}
|
216 |
+
- Total time in meetings: {stats['total_time_spent']}
|
217 |
+
- Busiest month: {stats['busiest_month']}
|
218 |
+
- Busiest day: {stats['busiest_day']}
|
219 |
+
- Average meeting duration: {stats['average_meeting_duration']}
|
220 |
+
- Most common meeting time: {stats['most_common_meeting_time']}
|
221 |
+
- Most frequent participant: {stats['most_frequent_participant']}
|
222 |
+
|
223 |
+
Return as JSON with format: {{"total_meetings_comment": "", "time_spent_comment": "", "busiest_times_comment": "", "collaborator_comment": "", "habits_comment": ""}}
|
224 |
+
"""
|
225 |
+
|
226 |
+
# Make LLM calls
|
227 |
+
try:
|
228 |
+
billionaire_response = json.loads(llm.complete(billionaire_prompt))
|
229 |
+
stats_comments = json.loads(llm.complete(stats_prompt))
|
230 |
+
|
231 |
+
# Add new fields to stats
|
232 |
+
stats["schedule_analysis"] = billionaire_response
|
233 |
+
stats["metric_insights"] = stats_comments
|
234 |
+
except (json.JSONDecodeError, Exception) as e:
|
235 |
+
print(f"Error processing LLM responses: {e}")
|
236 |
+
# Add empty defaults if LLM processing fails
|
237 |
+
stats["schedule_analysis"] = {"name": "Unknown", "reason": "Analysis unavailable"}
|
238 |
+
stats["metric_insights"] = {"total_meetings_comment": "", "time_spent_comment": "",
|
239 |
+
"busiest_times_comment": "", "collaborator_comment": "",
|
240 |
+
"habits_comment": ""}
|
241 |
|
242 |
+
return APIResponse(
|
243 |
+
success=True,
|
244 |
+
data=stats
|
245 |
+
)
|
246 |
+
else:
|
247 |
+
return APIResponse(
|
248 |
+
success=False,
|
249 |
+
error=events_response["error"] or "Failed to fetch calendar events"
|
250 |
+
)
|
|
|
251 |
|
252 |
+
except Exception as e:
|
|
|
|
|
|
|
|
|
253 |
return APIResponse(
|
254 |
success=False,
|
255 |
+
error=f"Failed to generate wrapped: {str(e)}"
|
256 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
def create_gradio_api():
|
259 |
service = CalendarService()
|