hf-actions commited on
Commit
fca2085
·
1 Parent(s): fe4b696

feat: run automatic generation at startup when RUN_ON_START=true

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -159,4 +159,30 @@ Ultra-realistic photography style, fine-art cinematic composition, calming mood,
159
  else:
160
  logger.error("Token validation failed — daily job will not start")
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  demo.launch()
 
159
  else:
160
  logger.error("Token validation failed — daily job will not start")
161
 
162
+ # Optionally run one immediate generation on startup (headless/autostart)
163
+ run_on_start = os.getenv("RUN_ON_START", "false").lower() in ("1", "true", "yes")
164
+ if run_on_start:
165
+ logger.info("RUN_ON_START enabled — validating tokens before immediate run")
166
+ if validate_tokens():
167
+ try:
168
+ prompt = os.getenv("DAILY_PROMPT")
169
+ if not prompt:
170
+ prompt = '''Create a photorealistic, serene Buddhist scene at sunrise. A calm Buddha statue in side profile, seated in meditation on a stone platform. Soft golden morning light with gentle rim lighting. Misty mountains and ancient Buddhist temple stupas fading into the background, creating depth and a peaceful spiritual atmosphere. Subtle haze, warm earth tones, cinematic lighting, natural stone textures, shallow depth of field. A tranquil lotus flower near still reflective water in the foreground.
171
+
172
+ Generate a short, original Buddhist-style quote about mindfulness, impermanence, inner peace, or awareness. The quote must be calm, timeless, and simple (no modern language, no slang). Keep it under 18 words.
173
+
174
+ Overlay the generated quote text in the center of the image using an elegant serif or handwritten-style font. The text should be softly glowing, perfectly legible, minimal, and harmonious with the scene. Avoid bold, modern, or decorative typography.
175
+
176
+ Ultra-realistic photography style, fine-art cinematic composition, calming mood, high detail, balanced contrast, 4K quality.'''
177
+ logger.info("Running one-time startup generate_and_post")
178
+ try:
179
+ res = generate_and_post(prompt, caption=None, post=True, use_wisdom_as_prompt=True, caption_template=None, use_wisdom_as_caption=True)
180
+ logger.info("Startup run result: %s", res)
181
+ except Exception:
182
+ logger.exception("Startup generate_and_post failed")
183
+ except Exception:
184
+ logger.exception("Immediate run crashed")
185
+ else:
186
+ logger.error("Token validation failed — immediate run will not start")
187
+
188
  demo.launch()