diff --git a/lib/ai_web_researcher/gpt_online_researcher.py b/lib/ai_web_researcher/gpt_online_researcher.py index 2cdfbad1..fd54594a 100644 --- a/lib/ai_web_researcher/gpt_online_researcher.py +++ b/lib/ai_web_researcher/gpt_online_researcher.py @@ -56,7 +56,9 @@ def gpt_web_researcher(search_keywords): def do_google_serp_search(search_keywords): - """ """ + """ COmmon function to do google SERP analysis and return results. """ + + # FIXME: Add a return filter to either return full json, titles, PAA, relatedsearches etc. try: logger.info(f"Doing Google search for: {search_keywords}\n") g_results = google_search(search_keywords) diff --git a/lib/ai_writers/facebook_ai_writer.py b/lib/ai_writers/facebook_ai_writer.py index 20987c95..5fc5e47a 100644 --- a/lib/ai_writers/facebook_ai_writer.py +++ b/lib/ai_writers/facebook_ai_writer.py @@ -1,50 +1,39 @@ -import time #Iwish +import time import os import json import requests import streamlit as st +from streamlit_quill import st_quill +from ..gpt_providers.text_generation.main_text_generation import llm_text_gen + def generate_facebook_post(business_type, target_audience, post_goal, post_tone, include, avoid): """ Generates a Facebook post prompt for an LLM based on user input. - - Args: - business_type: The type of business, e.g., fashion retailer, fitness coach. - target_audience: A description of the target audience. - post_goal: The goal of the Facebook post. - post_tone: The desired tone of the post. - include: Elements to include in the post (e.g., images, videos, links). - avoid: Elements to avoid in the post (e.g., long paragraphs, technical jargon). - - Returns: - A string containing the LLM prompt. """ - prompt = f"""I am a {business_type}. + prompt = f""" + I am a {business_type} looking to engage my target audience, {target_audience}, on Facebook. - Please help me write a detailed Facebook post that will engage my target audience, {target_audience}. + My goal for this detailed post is: {post_goal}. The tone should be {post_tone}. - Here are some additional details to consider: + Here are some additional preferences: + - **Include:** {include} + - **Avoid:** {avoid} - * **Post Goal:** {post_goal} - * **Post Tone:** {post_tone} - * **Include:** {include} - * **Avoid:** {avoid} + Please write a well-structured Facebook post with: + 1. A **catchy opening** to grab attention. + 2. Detailed **Engaging content** that highlights key benefits or features. + 3. A **strong call-to-action** (CTA) encouraging my audience to take action. + 4. If applicable, suggest **multimedia** (images, videos, etc.). + 5. Include **relevant hashtags** for visibility. - **Example Post Structure:** - - 1. **Attention-Grabbing Opening:** Start with a question or a bold statement to capture attention. - 2. **Engaging Content:** Briefly describe the main message or offer, highlighting key benefits or features. - 3. **Call-to-Action (CTA):** Encourage the audience to take a specific action (e.g., visit a link, comment, share). - 4. **Multimedia:** Mention the types of multimedia elements to include (e.g., images, videos). - 5. **Hashtags:** Include relevant hashtags to increase post visibility. - - """ + """ try: - response = generate_text_with_exception_handling(prompt) + response = llm_text_gen(prompt) return response except Exception as err: - st.error(f"An error occurred while generating the prompt: {e}") + st.error(f"An error occurred while generating the prompt: {err}") return None @@ -57,76 +46,74 @@ def facebook_post_writer(): """ ) - try: - col1, col2 = st.columns(2) + # Inputs for the Facebook post generator + col1, col2 = st.columns(2) - with col1: - post_goal_options = ["Promote a new product", "Share valuable content", "Increase engagement", "Customize"] - post_goal = st.selectbox( - "🎯 **What is the goal of your post?**", - post_goal_options, - index=2, - help="Select the main goal of your post." + with col1: + post_goal_options = ["Promote a new product", "Share valuable content", "Increase engagement", "Customize"] + post_goal = st.selectbox( + "🎯 **What is the goal of your post?**", + post_goal_options, + index=2, + help="Select the main goal of your post." + ) + + if post_goal == "Customize": + post_goal = st.text_input( + "🎯 **Customize your goal:**", + placeholder="e.g., Announce an event", + help="Provide a specific goal if you selected 'Customize'." + ) + target_audience = st.text_input( + "👥 **Describe your target audience:**", + placeholder="e.g., Fitness enthusiasts", + help="Describe the audience you are targeting with this post." + ) + include = st.text_input( + "📷 **What elements do you want to include?**", + placeholder="e.g., Short video with a sneak peek of the challenge", + help="Specify any elements you want to include in the post (e.g., images, videos, links, hashtags, questions)." + ) + + with col2: + post_tone_options = ["Informative", "Humorous", "Inspirational", "Upbeat", "Casual", "Customize"] + post_tone = st.selectbox( + "🎨 **What tone do you want to use?**", + post_tone_options, + index=3, + help="Choose the tone you want to use for the post." + ) + + if post_tone == "Customize": + post_tone = st.text_input( + "🎨 **Customize your tone:**", + placeholder="e.g., Professional", + help="Provide a specific tone if you selected 'Customize'." ) - if post_goal == "Customize": - post_goal = st.text_input( - "🎯 **Customize your goal:**", - placeholder="e.g., Announce an event", - help="Provide a specific goal if you selected 'Customize'." - ) - target_audience = st.text_input( - "👥 **Describe your target audience:**", - placeholder="e.g., Fitness enthusiasts", - help="Describe the audience you are targeting with this post." - ) - include = st.text_input( - "📷 **What elements do you want to include?**", - placeholder="e.g., Short video with a sneak peek of the challenge", - help="Specify any elements you want to include in the post (e.g., images, videos, links, hashtags, questions)." - ) + business_type = st.text_input( + "🏢 **What is your business type?**", + placeholder="e.g., Fitness coach", + help="Provide the type of your business. This will help tailor the post content." + ) - with col2: - post_tone_options = ["Informative", "Humorous", "Inspirational", "Upbeat", "Casual", "Customize"] - post_tone = st.selectbox( - "🎨 **What tone do you want to use?**", - post_tone_options, - index=3, - help="Choose the tone you want to use for the post." - ) + avoid = st.text_input( + "❌ **What elements do you want to avoid?**", + placeholder="e.g., Long paragraphs", + help="Specify any elements you want to avoid in the post (e.g., long paragraphs, technical jargon)." + ) - if post_tone == "Customize": - post_tone = st.text_input( - "🎨 **Customize your tone:**", - placeholder="e.g., Professional", - help="Provide a specific tone if you selected 'Customize'." - ) - - business_type = st.text_input( - "🏢 **What is your business type?**", - placeholder="e.g., Fitness coach", - help="Provide the type of your business. This will help tailor the post content." - ) - - avoid = st.text_input( - "❌ **What elements do you want to avoid?**", - placeholder="e.g., Long paragraphs", - help="Specify any elements you want to avoid in the post (e.g., long paragraphs, technical jargon)." - ) - - if st.button("🚀 Generate Facebook Post"): + # Handle the generation button + if st.button("🚀 Generate Facebook Post"): + with st.spinner(): if not business_type or not target_audience: st.error("🚫 Please provide the required inputs: Business Type and Target Audience.") else: generated_post = generate_facebook_post( business_type, target_audience, post_goal, post_tone, include, avoid ) + if generated_post: - st.subheader("**🧕 Verify: Alwrity can make mistakes.**") - st.write("## 📄 Generated Facebook Post:") - st.write(generated_post) - st.markdown("---") + st.markdown(generated_post) else: st.error("Error: Failed to generate Facebook Post.") - except Exception as e: - st.error(f"An error occurred: {e}") diff --git a/lib/ai_writers/linkedin_ai_writer.py b/lib/ai_writers/linkedin_ai_writer.py index 35ebc080..22e88fa6 100644 --- a/lib/ai_writers/linkedin_ai_writer.py +++ b/lib/ai_writers/linkedin_ai_writer.py @@ -4,6 +4,9 @@ import json import requests import streamlit as st +from ..gpt_providers.text_generation.main_text_generation import llm_text_gen +from ..ai_web_researcher.gpt_online_researcher import do_google_serp_search + def linked_post_writer(): # Title and description @@ -43,12 +46,12 @@ def generate_linkedin_post(input_blog_keywords, input_linkedin_type, input_linke """ Function to call upon LLM to get the work done. """ # Fetch SERP results & PAA questions for FAQ. - serp_results, people_also_ask = get_serp_results(input_blog_keywords) + serp_results, people_also_ask = do_google_serp_search(input_blog_keywords) # If keywords and content both are given. if serp_results: - prompt = f"""As a SEO expert and experienced linkedin content writer, - I will provide you with my 'blog keywords' and 'google serp results'. + prompt = f"""As an Experienced, industry veteran and experienced linkedin content writer, + I will provide you with my 'blog keywords' and 'google serp results' done for the keywords. Your task is to write a detailed linkedin post, using given keywords and search results. Follow below guidelines for generating the linkedin post: @@ -59,9 +62,15 @@ def generate_linkedin_post(input_blog_keywords, input_linkedin_type, input_linke 5). Optimise your response for blog type of {input_linkedin_type}. 6). Important to provide your response in {input_linkedin_language} language.\n - blog keywords: '{input_blog_keywords}'\n - google serp results: '{serp_results}' - people_also_ask: '{people_also_ask}' + Your final response should demostrate Experience, Expertise, Authoritativeness, and Trustworthiness. + + blog keywords: \'\'\'{input_blog_keywords}\'\'\' + google serp results: \'\'\'{serp_results}\'\'\' """ - linkedin_post = generate_text_with_exception_handling(prompt) - return linkedin_post + + try: + response = llm_text_gen(prompt) + return response + except Exception as err: + st.error(f"Failed to generate Open Graph tags: {err}") + return None