Auto-update: Thu Nov 14 11:38:18 PST 2024

This commit is contained in:
sanj 2024-11-14 11:38:18 -08:00
parent 2b638d4bf6
commit 3e33c5914f
2 changed files with 93 additions and 86 deletions

View file

@ -368,6 +368,7 @@ created: "{dt_datetime.now().strftime("%Y-%m-%d %H:%M:%S")}"
with open(absolute_path, 'wb') as f:
f.write(body.encode())
if Sys.EXTENSIONS.comfyui:
banner = await generate_banner(formatted_day, location, weather_note)
return absolute_path
@ -422,6 +423,7 @@ async def update_frontmatter(date_time: dt_datetime, key: str, value: str):
return {"message": "Frontmatter updated successfully."}
if Sys.EXTENSIONS.comfyui:
@note.post("/note/banner")
async def banner_endpoint(dt: str, location: str = None, forecast: str = None, mood: str = None, other_context: str = None):
'''
@ -430,12 +432,13 @@ async def banner_endpoint(dt: str, location: str = None, forecast: str = None, m
l.debug(f"banner_endpoint requested with date: {dt} ({type(dt)})")
date_time = await gis.dt(dt)
l.debug(f"date_time after localization: {date_time} ({type(date_time)})")
context = await generate_context(dt, location, forecast, mood, other_context)
context = await generate_banner_context(dt, location, forecast, mood, other_context)
jpg_path = await generate_banner(date_time, location, mood=mood, other_context=other_context)
return jpg_path
async def generate_banner(dt, location: Location = None, forecast: str = None, mood: str = None, other_context: str = None):
if Sys.EXTENSIONS.comfyui:
date_time = await gis.dt(dt)
destination_path, local_path = assemble_journal_path(date_time, filename="Banner", extension=".jpg", no_timestamp = True)
if not location or not isinstance(location, Location):
@ -445,7 +448,7 @@ async def generate_banner(dt, location: Location = None, forecast: str = None, m
if not forecast:
forecast = await update_dn_weather(date_time, False, location.latitude, location.longitude)
prompt = await generate_context(date_time, location, forecast, mood, other_context)
prompt = await generate_banner_context(date_time, location, forecast, mood, other_context)
l.debug(f"Prompt: {prompt}")
final_path = await img.workflow(prompt, scene=OBSIDIAN_BANNER_SCENE, destination_path=destination_path)
if not str(local_path) in str(final_path):
@ -453,9 +456,12 @@ async def generate_banner(dt, location: Location = None, forecast: str = None, m
jpg_embed = f"\"![[{local_path}]]\""
await update_frontmatter(date_time, "banner", jpg_embed)
return local_path
else:
l.warn(f"generate_banner called, but comfyui extension is disabled")
async def generate_context(date_time, location: Location, forecast: str, mood: str, other_context: str):
async def generate_banner_context(date_time, location: Location, forecast: str, mood: str, other_context: str):
if Sys.EXTENSIONS.comfyui:
display_name = "Location: "
if location and isinstance(location, Location):
lat, lon = location.latitude, location.longitude
@ -476,7 +482,7 @@ async def generate_context(date_time, location: Location, forecast: str, mood: s
if display_name == "Location: ":
geocoded_location = await GEO.code((lat, lon))
if geocoded_location.display_name or geocoded_location.city or geocoded_location.country:
return await generate_context(date_time, geocoded_location, forecast, mood, other_context)
return await generate_banner_context(date_time, geocoded_location, forecast, mood, other_context)
else:
l.warning(f"Failed to get a useable location for purposes of generating a banner, but we'll generate one anyway.")
elif location and isinstance(location, str):
@ -512,6 +518,8 @@ async def generate_context(date_time, location: Location, forecast: str, mood: s
prompt += "\n".join([display_name, forecast, mood, other_context])
return prompt
else:
l.warn(f"generate_banner_context called, but comfyui extension disabled")
async def get_note(date_time: dt_datetime):

File diff suppressed because one or more lines are too long