Spaces:
Sleeping
Sleeping
| import os | |
| import requests | |
| import time | |
| import json | |
| from openai import OpenAI # Ensure you have openai installed (pip install openai) | |
| # --- Configuration & Environment Variables --- | |
| # Make sure these are set as Hugging Face Space secrets! | |
| OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
| HEYGEN_API_KEY = os.getenv("HEYGEN_API_KEY") | |
| BLOTATO_API_KEY = os.getenv("BLOTATO_API_KEY") | |
| # Heygen specific setup (as defined in n8n's "Setup Heygen" node) | |
| HEYGEN_AVATAR_ID = os.getenv("HEYGEN_AVATAR_ID", "c67f3f55c5fd49d080e19a2ea9666e77") # Use env or default | |
| HEYGEN_VOICE_ID = os.getenv("HEYGEN_VOICE_ID", "e515d746526f448fa533afddc97e4933") # Use env or default | |
| HEYGEN_BACKGROUND_VIDEO_URL = os.getenv("HEYGEN_BACKGROUND_VIDEO_URL", "https://database.blotato.io/storage/v1/object/public/public_media/77fe579a-3dc0-49d9-8c1e-d1f49d99921f/videogen2-render-11c196cb-e2f4-4716-9095-eb98621d6433.mp4") # Use env or default | |
| # Blotato specific account IDs (from "Prepare for Publish" node) | |
| # It's better to get these from environment variables if they change per user/deployment | |
| BLOTATO_INSTAGRAM_ID = os.getenv("BLOTATO_INSTAGRAM_ID", "") | |
| BLOTATO_YOUTUBE_ID = os.getenv("BLOTATO_YOUTUBE_ID", "5174") | |
| BLOTATO_TIKTOK_ID = os.getenv("BLOTATO_TIKTOK_ID", "") | |
| BLOTATO_FACEBOOK_ID = os.getenv("BLOTATO_FACEBOOK_ID", "") | |
| BLOTATO_FACEBOOK_PAGE_ID = os.getenv("BLOTATO_FACEBOOK_PAGE_ID", "") | |
| BLOTATO_THREADS_ID = os.getenv("BLOTATO_THREADS_ID", "") | |
| BLOTATO_TWITTER_ID = os.getenv("BLOTATO_TWITTER_ID", "") | |
| BLOTATO_LINKEDIN_ID = os.getenv("BLOTATO_LINKEDIN_ID", "") | |
| BLOTATO_PINTEREST_ID = os.getenv("BLOTATO_PINTEREST_ID", "") | |
| BLOTATO_PINTEREST_BOARD_ID = os.getenv("BLOTATO_PINTEREST_BOARD_ID", "") | |
| BLOTATO_BLUESKY_ID = os.getenv("BLOTATO_BLUESKY_ID", "") | |
| # Initialize OpenAI client | |
| client = OpenAI(api_key=OPENAI_API_KEY) | |
| # --- Helper Functions for Hacker News (Replacing n8n's Hacker News Tool) --- | |
| def fetch_hn_top_stories(): | |
| """Fetches top story IDs from Hacker News.""" | |
| print("Fetching top Hacker News stories...") | |
| try: | |
| response = requests.get("https://hacker-news.firebaseio.com/v0/topstories.json") | |
| response.raise_for_status() | |
| return response.json() | |
| except requests.exceptions.RequestException as e: | |
| print(f"Error fetching top stories: {e}") | |
| return [] | |
| def fetch_hn_item(item_id): | |
| """Fetches details for a single Hacker News item (story or comment).""" | |
| try: | |
| response = requests.get(f"https://hacker-news.firebaseio.com/v0/item/{item_id}.json") | |
| response.raise_for_status() | |
| return response.json() | |
| except requests.exceptions.RequestException as e: | |
| print(f"Error fetching item {item_id}: {e}") | |
| return None | |
| def search_hn_for_ai_llm_stories(num_stories=10): | |
| """Fetches top stories and filters for AI/LLM related content.""" | |
| top_story_ids = fetch_hn_top_stories() | |
| ai_llm_stories = [] | |
| for i, story_id in enumerate(top_story_ids): | |
| if len(ai_llm_stories) >= num_stories: | |
| break | |
| story = fetch_hn_item(story_id) | |
| if story and 'title' in story and isinstance(story['title'], str): | |
| if "AI" in story['title'].upper() or "LLM" in story['title'].upper(): | |
| ai_llm_stories.append(story) | |
| print(f"Processed {i+1}/{len(top_story_ids)} top stories...") | |
| return ai_llm_stories | |
| def get_hn_article_and_comments(story_id): | |
| """Fetches a Hacker News article and its comments.""" | |
| article = fetch_hn_item(story_id) | |
| comments_data = [] | |
| if article and 'kids' in article: | |
| print(f"Fetching comments for story {story_id}...") | |
| for comment_id in article['kids']: | |
| comment = fetch_hn_item(comment_id) | |
| if comment and 'text' in comment: | |
| comments_data.append(comment['text']) | |
| return {"article": article, "comments": comments_data} | |
| # --- OpenAI Functions (Replacing n8n's OpenAI and Write Script/Caption nodes) --- | |
| def generate_ai_avatar_script(hn_data): | |
| """ | |
| Generates a 30-second monologue script for an AI avatar video based on HN data. | |
| Replicates the 'AI Agent' prompt. | |
| """ | |
| print("Generating AI avatar script...") | |
| if not OPENAI_API_KEY: | |
| raise ValueError("OPENAI_API_KEY not set for script generation.") | |
| # Format the Hacker News data for the prompt | |
| article_title = hn_data['article'].get('title', 'No title available') | |
| article_url = hn_data['article'].get('url', 'No URL available') | |
| article_text = f"Title: {article_title}\nURL: {article_url}\n" | |
| if hn_data['article'].get('text'): | |
| article_text += f"Content: {hn_data['article']['text']}\n" | |
| article_text += "\nComments:\n" + "\n".join(hn_data['comments'][:10]) # Limit comments for brevity | |
| prompt = f""" | |
| # INSTRUCTIONS | |
| Perform the following tasks, in order: | |
| 1. Fetch the top 10 stories from Hacker News from the past 24 hours related to AI or LLMs. | |
| 2. Select the top story that is most likely to go viral on social media. | |
| 3. Fetch the article and Hacker News comments. | |
| 4. Create a 30-second monologue script for an AI avatar video, following these guidelines: | |
| - The script should be approximately 30 seconds when spoken aloud. | |
| - Include lots of details and statistics from the article. | |
| - Use 6th grade reading level. | |
| - Balanced viewpoint. | |
| - Script should be in single paragraph | |
| 5. Update the script's first 2 sentences to use sensational viral hooks that grab the viewer's attention and spark curiosity. The 3rd sentence should start diving into the article's details. | |
| 6. Replace the last sentence with: "Hit follow to stay ahead in AI!" | |
| # OUTPUT FORMAT | |
| ONLY output the exact video script. Do not output anything else. NEVER include intermediate thoughts, notes, or formatting. | |
| # INPUT | |
| Use the following information sources: | |
| <sources> | |
| {article_text} | |
| </sources> | |
| """ | |
| try: | |
| completion = client.chat.completions.create( | |
| model="gpt-4o-mini", # From n8n config for "Write Script" / "AI Agent" | |
| messages=[ | |
| {"role": "user", "content": prompt} | |
| ], | |
| temperature=0.7 # A reasonable default, adjust if needed | |
| ) | |
| return completion.choices[0].message.content.strip() | |
| except Exception as e: | |
| print(f"Error generating AI avatar script: {e}") | |
| return "Failed to generate script." | |
| def generate_long_caption(script_content): | |
| """ | |
| Generates a long caption based on the video script, replicating 'Write Long Caption' node. | |
| """ | |
| print("Generating long caption...") | |
| if not OPENAI_API_KEY: | |
| raise ValueError("OPENAI_API_KEY not set for long caption generation.") | |
| prompt = f""" | |
| =# EXAMPLE | |
| <example> | |
| Many people have recently asked me about ask engine optimization, which is all about optimizing your website and existing content, so it can be pulled into ChatGPT and other generative AI tools. Consider that generative AI tools tend to be more conversational in nature and have a Q&A type format, so search engines will want to pull in snippets that concisely answer a user’s question.- what is ask engine optimization in the age of AI?- How does traditional SEO compare to ask engine optimization today?- top tips and tricks to get started with ask engine optimization? | |
| #ai #askengineoptimization #chatgpts #seo #aitools #digitalmarketing | |
| </example> | |
| # CONTEXT | |
| Infer the topic from the sources provided. | |
| # WRITING STYLE | |
| Here’s how you always write: | |
| <writing_style> | |
| - Your writing style is spartan and informative. | |
| - Use clear, simple language. | |
| - Employ short, impactful sentences. | |
| - Use active voice; avoid passive voice. | |
| - Focus on practical, actionable insights. | |
| - Incorporate data or statistics to support claims when possible. | |
| - Use \"\"\"\"\"\"\"\"you\"\"\"\"\"\"\"\" and \"\"\"\"\"\"\"\"your\"\"\"\"\"\"\"\" to directly address the reader. | |
| - Avoid metaphors and clichés. | |
| - Avoid generalizations. | |
| - Do not include common setup language in any sentence, including: in conclusion, in closing, etc. | |
| - Do not output warnings or notes—just the output requested. | |
| - Do not use hashtags. | |
| - Do not use semicolons. | |
| - Do not use emojis. | |
| - Do not use asterisks. | |
| - Do NOT use these words: | |
| \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"can, may, just, that, very, really, literally, actually, certainly, probably, basically, could, maybe, delve, embark, enlightening, esteemed, shed light, craft, crafting, imagine, realm, game-changer, unlock, discover, skyrocket, abyss, you're not alone, in a world where, revolutionize, disruptive, utilize, utilizing, dive deep, tapestry, illuminate, unveil, pivotal, enrich, intricate, elucidate, hence, furthermore, realm, however, harness, exciting, groundbreaking, cutting-edge, remarkable, it. remains to be seen, glimpse into, navigating, landscape, stark, testament, in summary, in conclusion, moreover, boost, bustling, opened up, powerful, inquiries, ever-evolving\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" | |
| </writing_style> | |
| # PLANNING | |
| Your goal is to write a 50-word video caption based on the provided source. | |
| 1. Analyze the provided sources thoroughly. | |
| 2. Study the <example> post carefully. You will be asked to replicate their: | |
| - Overall structure. | |
| - Tone and voice. | |
| - Formatting (including line breaks and spacing). | |
| - Length (aim for a similarly detailed post). | |
| - Absence of emojis. | |
| - Use of hashtags. | |
| - Emotional resonance. | |
| # OUTPUT | |
| Follow the GUIDELINES below to write the post. Use your analysis from step 1 and step 2. Use the provided sources as the foundation for your post, expanding on it significantly while maintaining the style and structure of the examples provided from step 2. You MUST use information from the provided sources. Make sure you adhere to your <writing_style>. | |
| <guidelines> | |
| The description should be structured as follows: | |
| 1. Start with 1 paragraph summarizing the source | |
| 2. Newline, followed by 3 bullet points of questions that a viewer might ask on a search engine about the source | |
| 3. Newline, followed by these hashtags: #ai #artificialintelligence #ainews #sabrinaramonov #aiavatar | |
| </guidelines> | |
| Take a deep breath and take it step-by-step! | |
| # INPUT | |
| Use the following information sources: | |
| <sources> | |
| {script_content} | |
| </sources> | |
| """ | |
| try: | |
| completion = client.chat.completions.create( | |
| model="gpt-4o", # From n8n config | |
| messages=[ | |
| {"role": "user", "content": prompt} | |
| ], | |
| temperature=0.7 # A reasonable default | |
| ) | |
| return completion.choices[0].message.content.strip() | |
| except Exception as e: | |
| print(f"Error generating long caption: {e}") | |
| return "Failed to generate long caption." | |
| def generate_short_caption(long_caption_content): | |
| """ | |
| Generates a short caption based on the long caption, replicating 'Write Short Caption' node. | |
| """ | |
| print("Generating short caption...") | |
| if not OPENAI_API_KEY: | |
| raise ValueError("OPENAI_API_KEY not set for short caption generation.") | |
| prompt = f""" | |
| =Write a spartan 2-sentence caption summarizing the video content, use 6th grade language, balanced neutral perspective, no emojis: | |
| <content> | |
| {long_caption_content} | |
| </content> | |
| """ | |
| try: | |
| completion = client.chat.completions.create( | |
| model="gpt-4o", # From n8n config | |
| messages=[ | |
| {"role": "user", "content": prompt} | |
| ], | |
| temperature=0.7 # A reasonable default | |
| ) | |
| return completion.choices[0].message.content.strip() | |
| except Exception as e: | |
| print(f"Error generating short caption: {e}") | |
| return "Failed to generate short caption." | |
| # --- Heygen API Interactions --- | |
| def create_avatar_video(script_text): | |
| """Replicates 'Create Avatar Video' node.""" | |
| print("Calling Heygen API to create avatar video...") | |
| if not HEYGEN_API_KEY: | |
| raise ValueError("HEYGEN_API_KEY not set for Heygen video creation.") | |
| headers = { | |
| "X-Api-Key": HEYGEN_API_KEY, | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "video_inputs": [ | |
| { | |
| "character": { | |
| "type": "avatar", | |
| "avatar_id": HEYGEN_AVATAR_ID, | |
| "avatar_style": "normal", | |
| "scale": 1.0, | |
| "offset": {"x": 0.0, "y": 0.0}, | |
| "matting": True | |
| }, | |
| "voice": { | |
| "type": "text", | |
| "input_text": script_text, | |
| "voice_id": HEYGEN_VOICE_ID, | |
| "speed": 1.1, | |
| "pitch": 50, | |
| "emotion": "Excited" | |
| }, | |
| "background": { | |
| "type": "video", | |
| "url": HEYGEN_BACKGROUND_VIDEO_URL, | |
| "play_style": "loop", | |
| "fit": "cover" | |
| } | |
| } | |
| ], | |
| "dimension": {"width": 720, "height": 1280}, | |
| "aspect_ratio": "9:16", | |
| "caption": False, | |
| "title": "n8n TEST AVATAR" | |
| } | |
| try: | |
| response = requests.post("https://api.heygen.com/v2/video/generate", headers=headers, json=payload) | |
| response.raise_for_status() | |
| return response.json() | |
| except requests.exceptions.RequestException as e: | |
| print(f"Error creating Heygen video: {e}") | |
| raise | |
| def get_avatar_video_status(video_id): | |
| """Replicates 'Get Avatar Video' node.""" | |
| print(f"Checking Heygen video status for video_id: {video_id}...") | |
| if not HEYGEN_API_KEY: | |
| raise ValueError("HEYGEN_API_KEY not set for Heygen video status check.") | |
| headers = { | |
| "X-Api-Key": HEYGEN_API_KEY | |
| } | |
| params = {"video_id": video_id} | |
| try: | |
| response = requests.get("https://api.heygen.com/v1/video_status.get", headers=headers, params=params) | |
| response.raise_for_status() | |
| return response.json() | |
| except requests.exceptions.RequestException as e: | |
| print(f"Error getting Heygen video status: {e}") | |
| raise | |
| # --- Blotato API Interactions --- | |
| def upload_to_blotato(media_url, is_image=False): | |
| """Replicates 'Upload to Blotato' and 'Upload to Blotato - Image' nodes.""" | |
| print(f"Uploading media to Blotato: {media_url}...") | |
| if not BLOTATO_API_KEY: | |
| raise ValueError("BLOTATO_API_KEY not set for Blotato upload.") | |
| headers = { | |
| "blotato-api-key": BLOTATO_API_KEY, | |
| "Content-Type": "application/json" | |
| } | |
| payload = {"url": media_url} | |
| try: | |
| response = requests.post("https://backend.blotato.com/v2/media", headers=headers, json=payload) | |
| response.raise_for_status() | |
| return response.json() | |
| except requests.exceptions.RequestException as e: | |
| print(f"Error uploading to Blotato: {e}") | |
| raise | |
| def publish_to_blotato( | |
| platform, | |
| media_url, | |
| account_id, | |
| text_content, | |
| facebook_page_id=None, # Only for Facebook | |
| youtube_title=None, # Only for YouTube | |
| pinterest_board_id=None, # Only for Pinterest | |
| pinterest_link=None # Only for Pinterest | |
| ): | |
| """ | |
| Replicates various '[Platform] Publish via Blotato' nodes. | |
| Combines logic for different platforms. | |
| """ | |
| print(f"Publishing to Blotato ({platform})...") | |
| if not BLOTATO_API_KEY: | |
| raise ValueError("BLOTATO_API_KEY not set for Blotato publishing.") | |
| headers = { | |
| "blotato-api-key": BLOTATO_API_KEY, | |
| "Content-Type": "application/json" | |
| } | |
| post_data = { | |
| "post": { | |
| "target": {"targetType": platform}, | |
| "content": { | |
| "text": text_content, | |
| "platform": platform, | |
| "mediaUrls": [media_url] if media_url else [] | |
| }, | |
| "accountId": account_id | |
| } | |
| } | |
| # Add platform-specific target parameters | |
| if platform == "facebook" and facebook_page_id: | |
| post_data["post"]["target"]["pageId"] = facebook_page_id | |
| elif platform == "youtube": | |
| post_data["post"]["target"]["title"] = youtube_title or "Generated Video" | |
| post_data["post"]["target"]["privacyStatus"] = "public" | |
| post_data["post"]["target"]["shouldNotifySubscribers"] = True | |
| elif platform == "tiktok": | |
| # These are fixed in the n8n node, can be added here | |
| post_data["post"]["target"].update({ | |
| "isYourBrand": False, "disabledDuet": False, "privacyLevel": "PUBLIC_TO_EVERYONE", | |
| "isAiGenerated": False, "disabledStitch": False, "disabledComments": False, | |
| "isBrandedContent": False | |
| }) | |
| elif platform == "pinterest" and pinterest_board_id: | |
| post_data["post"]["target"]["boardId"] = pinterest_board_id | |
| post_data["post"]["target"]["link"] = pinterest_link or "https://www.tiktok.com/@sabrina_ramonov" | |
| elif platform == "bluesky": | |
| # Bluesky node in n8n had empty mediaUrls, implying image/video not supported or disabled. | |
| # Following that for now. | |
| post_data["post"]["content"]["mediaUrls"] = [] | |
| try: | |
| response = requests.post("https://backend.blotato.com/v2/posts", headers=headers, json=post_data) | |
| response.raise_for_status() | |
| print(f"Successfully published to {platform}.") | |
| return response.json() | |
| except requests.exceptions.RequestException as e: | |
| print(f"Error publishing to {platform}: {e}") | |
| # Continue even if one platform fails | |
| return {"status": "failed", "error": str(e)} | |
| # --- Main Workflow Execution Function --- | |
| def run_daily_ai_video_workflow(): | |
| """ | |
| Executes the entire workflow, simulating the n8n flow. | |
| """ | |
| print("--- Starting Daily AI Video Workflow ---") | |
| results = {} | |
| try: | |
| # 1. AI Agent (combining Fetch HN Front Page, Fetch HN Article, and Write Script logic) | |
| # This is simplified; a real Langchain agent would dynamically decide which tools to use. | |
| # Here, we hardcode the flow as per the n8n workflow. | |
| ai_llm_stories = search_hn_for_ai_llm_stories(num_stories=10) | |
| if not ai_llm_stories: | |
| print("No AI/LLM stories found on Hacker News front page.") | |
| return {"status": "failed", "message": "No relevant Hacker News stories."} | |
| # For simplicity, pick the first one that matches | |
| selected_story = ai_llm_stories[0] | |
| hn_data = get_hn_article_and_comments(selected_story['id']) | |
| if not hn_data['article']: | |
| print(f"Could not fetch details for selected HN story {selected_story['id']}.") | |
| return {"status": "failed", "message": "Could not fetch HN article details."} | |
| ai_avatar_script = generate_ai_avatar_script(hn_data) | |
| if ai_avatar_script == "Failed to generate script.": | |
| return {"status": "failed", "message": "AI script generation failed."} | |
| results['ai_avatar_script'] = ai_avatar_script | |
| print(f"Generated AI Avatar Script:\n{ai_avatar_script}\n") | |
| # 2. Write Long Caption | |
| final_text_long = generate_long_caption(ai_avatar_script) | |
| results['final_text_long'] = final_text_long | |
| print(f"Generated Long Caption:\n{final_text_long}\n") | |
| # 3. Write Short Caption | |
| final_text_short = generate_short_caption(final_text_long) | |
| results['final_text_short'] = final_text_short | |
| print(f"Generated Short Caption:\n{final_text_short}\n") | |
| # 4. Create Avatar Video (Heygen) | |
| create_video_response = create_avatar_video(ai_avatar_script) | |
| video_id = create_video_response['data']['video_id'] | |
| results['heygen_video_id'] = video_id | |
| print(f"Heygen Video ID: {video_id}") | |
| # 5. Wait | |
| # The n8n node has an 8-minute wait. In a real scenario, you'd poll for status. | |
| # For a simple deployment, a fixed wait might be acceptable, but polling is robust. | |
| print("Waiting 8 minutes for Heygen video to process...") | |
| time.sleep(8 * 60) # 8 minutes | |
| # 6. Get Avatar Video Status | |
| video_status_response = get_avatar_video_status(video_id) | |
| video_url = video_status_response['data']['video_url'] | |
| results['heygen_video_url'] = video_url | |
| print(f"Heygen Video URL: {video_url}") | |
| if not video_url: | |
| print("Heygen video URL not available after waiting. Cannot proceed with publishing.") | |
| return {"status": "failed", "message": "Heygen video URL not retrieved."} | |
| # 7. Prepare for Publish (variables gathered earlier or from workflow outputs) | |
| # This step is handled by variables in Python. | |
| # 8. Upload to Blotato (Video) | |
| blotato_upload_response = upload_to_blotato(video_url) | |
| blotato_media_url = blotato_upload_response['url'] # Blotato returns a URL for the uploaded media | |
| results['blotato_video_url'] = blotato_media_url | |
| print(f"Blotato Uploaded Video URL: {blotato_media_url}") | |
| # 9. Publish to Social Media via Blotato | |
| # Note: Some nodes were disabled in your n8n workflow. I'll include them here | |
| # but you might want to uncomment/enable them as needed. | |
| # [Youtube] Publish via Blotato (Active in n8n) | |
| publish_to_blotato( | |
| "youtube", blotato_media_url, BLOTATO_YOUTUBE_ID, final_text_long, | |
| youtube_title="TEST VIDEO" # As per n8n config | |
| ) | |
| # The following are DISABLED in the provided n8n workflow. | |
| # Uncomment and provide correct BLOTATO_ACCOUNT_IDs if you enable them. | |
| # [Instagram] Publish via Blotato | |
| # publish_to_blotato("instagram", blotato_media_url, BLOTATO_INSTAGRAM_ID, final_text_long) | |
| # [Facebook] Publish via Blotato | |
| # publish_to_blotato("facebook", blotato_media_url, BLOTATO_FACEBOOK_ID, final_text_long, facebook_page_id=BLOTATO_FACEBOOK_PAGE_ID) | |
| # [Threads] Publish via Blotato | |
| # publish_to_blotato("threads", blotato_media_url, BLOTATO_THREADS_ID, final_text_short) | |
| # [Linkedin] Publish via Blotato | |
| # publish_to_blotato("linkedin", blotato_media_url, BLOTATO_LINKEDIN_ID, final_text_long) | |
| # [Twitter] Publish via Blotato | |
| # publish_to_blotato("twitter", blotato_media_url, BLOTATO_TWITTER_ID, final_text_short) | |
| # [Tiktok] Publish via Blotato | |
| # publish_to_blotato("tiktok", blotato_media_url, BLOTATO_TIKTOK_ID, final_text_long) | |
| # [Bluesky] Publish via Blotato (Media URL is empty in n8n, following that) | |
| # publish_to_blotato("bluesky", None, BLOTATO_BLUESKY_ID, final_text_short) | |
| # 10. OpenAI (Image generation) + Upload to Blotato (Image) + Pinterest Publish | |
| # These were also DISABLED in n8n, but showing how they'd be integrated. | |
| # This would require actual image generation from OpenAI (DALL-E) and its URL. | |
| # For now, this part remains conceptual as it's disabled in the source workflow. | |
| # if False: # Only run if you enable this part | |
| # print("Attempting image generation and Pinterest publish...") | |
| # # Example: Generate image (you'd need to adapt for OpenAI's image generation API) | |
| # # image_response = client.images.generate(model="dall-e-3", prompt=final_text_long, n=1, size="1024x1024") | |
| # # generated_image_url = image_response.data[0].url | |
| # # blotato_image_upload_response = upload_to_blotato(generated_image_url, is_image=True) | |
| # # blotato_uploaded_image_url = blotato_image_upload_response['url'] | |
| # # publish_to_blotato("pinterest", blotato_uploaded_image_url, BLOTATO_PINTEREST_ID, final_text_short, pinterest_board_id=BLOTATO_PINTEREST_BOARD_ID, pinterest_link="https://www.tiktok.com/@sabrina_ramonov") | |
| except Exception as e: | |
| print(f"Workflow execution failed: {e}") | |
| return {"status": "failed", "message": str(e), "results": results} | |
| print("--- Workflow Completed Successfully ---") | |
| return {"status": "success", "message": "Workflow executed successfully!", "results": results} | |
| if __name__ == "__main__": | |
| # Example of how to run locally for testing (after setting environment variables) | |
| # python-dotenv can be used for local development: pip install python-dotenv | |
| # from dotenv import load_dotenv | |
| # load_dotenv() # Loads variables from a .env file if present | |
| # This will run the workflow directly when the script is executed | |
| run_daily_ai_video_workflow() |