Spaces:
Sleeping
A newer version of the Gradio SDK is available:
6.5.1
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)
- Install dependencies:
python -m pip install -r requirements.txt
- Create a local
.env(do NOT commit it). Example keys used by the app:
FB_PAGE_IDβ the numeric Page IDFB_PAGE_ACCESS_TOKENβ a Page access token withpages_manage_posts/ publish permissionsOPENAI_API_KEYβ (optional) OpenAI API key if using OpenAI image generationREPLICATE_API_TOKENβ (optional) Replicate API key if using ReplicateREPLICATE_MODELβ (optional) default replicate model ref (owner/name:version), e.g.google/nano-bananaPROVIDER_ORDERβ (optional) e.g.replicate,openaioropenai,replicate(defaultopenai,replicate)RUN_DAILY_REPLICATEβ (optional)trueto enable scheduled daily runs insideapp.pyDAILY_INTERVAL_HOURSβ (optional) schedule interval in hours (default24)DAILY_PROMPTβ (optional) override prompt for scheduled runs
Deploying to Hugging Face Spaces
- In your Space settings, set the following Secrets (Settings β Secrets):
FB_PAGE_ACCESS_TOKENFB_PAGE_IDREPLICATE_API_TOKEN(if you plan to use Replicate)OPENAI_API_KEY(if you plan to use OpenAI)PROVIDER_ORDER(optional)RUN_DAILY_REPLICATE(set totrueto enable daily runs)
- Ensure
app.pyandrequirements.txtare present at the repository root. The Space entrypoint isapp.py(specified in the metadata above).
Notes and recommendations
- The app spawns a daemon background thread for scheduled runs when
RUN_DAILY_REPLICATEis 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.txtincludes 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.txtgenerate_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
- Install dependencies:
python -m pip install -r requirements.txt
- Populate your
.env(do not commit secrets). Example keys used by the script:
FB_PAGE_IDβ the numeric Page IDFB_PAGE_ACCESS_TOKENβ a Page access token withpages_manage_postsor appropriate publish permissionsMESSAGEβ optional default messageLINKβ optional link to attach
Usage
Run directly with a message:
python post_to_facebook.py --message "Hello from script"
Or rely on MESSAGE in .env:
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.