Spaces:
Sleeping
Sleeping
| title: Wisdom Poster | |
| emoji: πͺ· | |
| colorFrom: indigo | |
| colorTo: indigo | |
| sdk: gradio | |
| sdk_version: 6.2.0 | |
| app_file: app.py | |
| pinned: false | |
| # Wisdom Poster β Hugging Face Space | |
| This Space generates short wisdom text and a matching image, then posts the result to a Facebook Page. The app supports both OpenAI and Replicate image generation; it will try providers in the order configured by the `PROVIDER_ORDER` environment variable (default: `openai,replicate`). | |
| Quick setup (local) | |
| 1. Install dependencies: | |
| ```bash | |
| python -m pip install -r requirements.txt | |
| ``` | |
| 2. Create a local `.env` (do NOT commit it). Example keys used by the app: | |
| - `FB_PAGE_ID` β the numeric Page ID | |
| - `FB_PAGE_ACCESS_TOKEN` β a Page access token with `pages_manage_posts` / publish permissions | |
| - `OPENAI_API_KEY` β (optional) OpenAI API key if using OpenAI image generation | |
| - `REPLICATE_API_TOKEN` β (optional) Replicate API key if using Replicate | |
| - `REPLICATE_MODEL` β (optional) default replicate model ref (owner/name:version), e.g. `google/nano-banana` | |
| - `PROVIDER_ORDER` β (optional) e.g. `replicate,openai` or `openai,replicate` (default `openai,replicate`) | |
| - `RUN_DAILY_REPLICATE` β (optional) `true` to enable scheduled daily runs inside `app.py` | |
| - `DAILY_INTERVAL_HOURS` β (optional) schedule interval in hours (default `24`) | |
| - `DAILY_PROMPT` β (optional) override prompt for scheduled runs | |
| Deploying to Hugging Face Spaces | |
| 1. In your Space settings, set the following Secrets (Settings β Secrets): | |
| - `FB_PAGE_ACCESS_TOKEN` | |
| - `FB_PAGE_ID` | |
| - `REPLICATE_API_TOKEN` (if you plan to use Replicate) | |
| - `OPENAI_API_KEY` (if you plan to use OpenAI) | |
| - `PROVIDER_ORDER` (optional) | |
| - `RUN_DAILY_REPLICATE` (set to `true` to enable daily runs) | |
| 2. Ensure `app.py` and `requirements.txt` are present at the repository root. The Space entrypoint is `app.py` (specified in the metadata above). | |
| Notes and recommendations | |
| - The app spawns a daemon background thread for scheduled runs when `RUN_DAILY_REPLICATE` is enabled. This works while the Space process is active but can be interrupted during redeploys β for guaranteed scheduling, use an external scheduler. | |
| - Keep your Space private if you do not want the public to access the UI or to expose functionality. | |
| - Monitor usage and API costs for OpenAI/Replicate. | |
| Troubleshooting | |
| - If the Space fails to start, check the `requirements.txt` includes all needed packages and that Secrets are set. | |
| - Use the Space logs (Settings β Logs) to inspect runtime errors. | |
| Minimal files to leave in the Space repo | |
| - `app.py` (entrypoint) | |
| - `requirements.txt` | |
| - `generate_image.py`, `generate_wisdom.py`, `post_to_facebook.py` | |
| - `.gitignore` (ignore `.env`, generated images) | |
| If you want, I can also add a short *Deploy checklist* file with exact steps and screenshot guidance for adding Secrets in the HF UI. | |
| # Post to Facebook Page | |
| This repository includes a small Python script to post a message to a Facebook Page using a Page Access Token stored in a `.env` file. | |
| Setup | |
| 1. Install dependencies: | |
| ```bash | |
| python -m pip install -r requirements.txt | |
| ``` | |
| 2. Populate your `.env` (do not commit secrets). Example keys used by the script: | |
| - `FB_PAGE_ID` β the numeric Page ID | |
| - `FB_PAGE_ACCESS_TOKEN` β a Page access token with `pages_manage_posts` or appropriate publish permissions | |
| - `MESSAGE` β optional default message | |
| - `LINK` β optional link to attach | |
| Usage | |
| Run directly with a message: | |
| ```bash | |
| python post_to_facebook.py --message "Hello from script" | |
| ``` | |
| Or rely on `MESSAGE` in `.env`: | |
| ```bash | |
| python post_to_facebook.py | |
| ``` | |
| Notes | |
| - The script posts to the Graph API endpoint `/{page-id}/feed`. | |
| - If you need long-lived tokens or other flows, exchange tokens using Facebook's API before placing them in `.env`. |