Spaces:
Sleeping
Sleeping
hf-actions
commited on
Commit
·
b3ab169
1
Parent(s):
5f2de2a
chore: add GitHub Actions daily runner and disable Space scheduled job
Browse files- .github/workflows/daily-post.yml +35 -0
- scripts/run_daily.py +31 -0
.github/workflows/daily-post.yml
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Daily Wisdom Post
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
schedule:
|
| 5 |
+
- cron: '0 9 * * *' # daily at 09:00 UTC — change as needed
|
| 6 |
+
workflow_dispatch: {}
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
build-and-post:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
env:
|
| 12 |
+
FB_PAGE_ID: ${{ secrets.FB_PAGE_ID }}
|
| 13 |
+
FB_PAGE_ACCESS_TOKEN: ${{ secrets.FB_PAGE_ACCESS_TOKEN }}
|
| 14 |
+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
| 15 |
+
REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }}
|
| 16 |
+
DAILY_PROMPT: ${{ secrets.DAILY_PROMPT }}
|
| 17 |
+
steps:
|
| 18 |
+
- uses: actions/checkout@v4
|
| 19 |
+
- name: Set up Python
|
| 20 |
+
uses: actions/setup-python@v4
|
| 21 |
+
with:
|
| 22 |
+
python-version: '3.10'
|
| 23 |
+
- name: Install dependencies
|
| 24 |
+
run: |
|
| 25 |
+
python -m pip install --upgrade pip
|
| 26 |
+
pip install -r requirements.txt
|
| 27 |
+
- name: Run daily post
|
| 28 |
+
run: |
|
| 29 |
+
python scripts/run_daily.py
|
| 30 |
+
- name: Upload generated images (optional)
|
| 31 |
+
if: success()
|
| 32 |
+
uses: actions/upload-artifact@v4
|
| 33 |
+
with:
|
| 34 |
+
name: generated-images
|
| 35 |
+
path: generated_images/
|
scripts/run_daily.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import logging
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
|
| 5 |
+
load_dotenv()
|
| 6 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
|
| 7 |
+
logger = logging.getLogger(__name__)
|
| 8 |
+
|
| 9 |
+
from generate_image import generate_and_post
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def main():
|
| 13 |
+
prompt = os.getenv("DAILY_PROMPT") or ""
|
| 14 |
+
# generate_and_post will raise on unrecoverable errors; exceptions are surfaced to GH Actions
|
| 15 |
+
try:
|
| 16 |
+
logger.info("Running daily generate_and_post with prompt: %s", (prompt[:80] + "...") if len(prompt) > 80 else prompt)
|
| 17 |
+
res = generate_and_post(prompt, caption=None, post=True, use_wisdom_as_prompt=True, use_wisdom_as_caption=True)
|
| 18 |
+
logger.info("Result: %s", res)
|
| 19 |
+
# Optionally save result to file for GH Actions artifact
|
| 20 |
+
out_path = os.path.join(os.getcwd(), "daily_result.json")
|
| 21 |
+
import json
|
| 22 |
+
with open(out_path, "w", encoding="utf-8") as f:
|
| 23 |
+
json.dump(res, f, default=str)
|
| 24 |
+
print("WROTE:", out_path)
|
| 25 |
+
except Exception:
|
| 26 |
+
logger.exception("Daily run failed")
|
| 27 |
+
raise
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
main()
|