Spaces:
Sleeping
Sleeping
Update pages/Latest.py
Browse files- pages/Latest.py +69 -9
pages/Latest.py
CHANGED
|
@@ -17,7 +17,6 @@ load_dotenv(override=True)
|
|
| 17 |
gemini_api_key = os.getenv("GEMINI_API_KEY")
|
| 18 |
|
| 19 |
|
| 20 |
-
|
| 21 |
# Latest Information Blog
|
| 22 |
from search_queries_generator import generate_queries
|
| 23 |
from blog_title_generator import blog_titles_agent
|
|
@@ -25,6 +24,12 @@ from blog_content_generator import blog_content_agent
|
|
| 25 |
from image_fomatted_blog_generator import image_formatted_blog
|
| 26 |
from image_prompts_generator import image_prompts
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# LLM
|
| 30 |
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key) # type:ignore
|
|
@@ -37,6 +42,12 @@ class BlogState(TypedDict):
|
|
| 37 |
blog_topics: List[str]
|
| 38 |
final_topic: str
|
| 39 |
blog_content: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
image_formated_blog: str
|
| 41 |
prompts: Dict[str, str]
|
| 42 |
|
|
@@ -56,18 +67,47 @@ graph1 = builder1.compile()
|
|
| 56 |
# Graph 2:
|
| 57 |
builder2 = StateGraph(BlogState)
|
| 58 |
builder2.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
|
|
|
|
|
|
|
| 59 |
builder2.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
|
| 60 |
builder2.add_node("image_prompts", lambda state: image_prompts(llm, state))
|
| 61 |
|
| 62 |
builder2.add_edge(START, "blog_agent")
|
| 63 |
-
builder2.add_edge("blog_agent", "
|
|
|
|
|
|
|
| 64 |
builder2.add_edge("image_formatted_blog", "image_prompts")
|
| 65 |
builder2.add_edge("image_prompts", END)
|
|
|
|
| 66 |
graph2 = builder2.compile()
|
| 67 |
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
st.title("Generate Latest Information Blog")
|
|
|
|
| 71 |
input_data = st.text_input("Enter a Category for your blog:")
|
| 72 |
|
| 73 |
if 'titles' not in st.session_state:
|
|
@@ -88,11 +128,31 @@ if input_data: # Only proceed if input_data is not empty
|
|
| 88 |
if st.session_state.titles:
|
| 89 |
st.session_state.selected_title = st.selectbox("Pick the Title for your Blog", st.session_state.titles)
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
|
|
|
|
| 17 |
gemini_api_key = os.getenv("GEMINI_API_KEY")
|
| 18 |
|
| 19 |
|
|
|
|
| 20 |
# Latest Information Blog
|
| 21 |
from search_queries_generator import generate_queries
|
| 22 |
from blog_title_generator import blog_titles_agent
|
|
|
|
| 24 |
from image_fomatted_blog_generator import image_formatted_blog
|
| 25 |
from image_prompts_generator import image_prompts
|
| 26 |
|
| 27 |
+
from company_content_generator import company_content
|
| 28 |
+
from marketed_blog import marketed_blog
|
| 29 |
+
from seo_keywords import seo_keywords
|
| 30 |
+
from seo_optimized_content_generator import seo_optimized_content_with_marketing
|
| 31 |
+
from seo_optimized_content_generator import simple_seo_optimized_content
|
| 32 |
+
|
| 33 |
|
| 34 |
# LLM
|
| 35 |
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key) # type:ignore
|
|
|
|
| 42 |
blog_topics: List[str]
|
| 43 |
final_topic: str
|
| 44 |
blog_content: str
|
| 45 |
+
url: str #//
|
| 46 |
+
contact_us_url: str #//
|
| 47 |
+
company_information: str #//
|
| 48 |
+
company_marketed_blog: str #//
|
| 49 |
+
seo_keywords: str #//
|
| 50 |
+
seo_optimized_blog: str #//
|
| 51 |
image_formated_blog: str
|
| 52 |
prompts: Dict[str, str]
|
| 53 |
|
|
|
|
| 67 |
# Graph 2:
|
| 68 |
builder2 = StateGraph(BlogState)
|
| 69 |
builder2.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
|
| 70 |
+
builder2.add_node("seo_keyword", lambda state: seo_keywords(state)) # //
|
| 71 |
+
builder2.add_node("simple_seo_blog", lambda state: simple_seo_optimized_content(llm, state)) # //
|
| 72 |
builder2.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
|
| 73 |
builder2.add_node("image_prompts", lambda state: image_prompts(llm, state))
|
| 74 |
|
| 75 |
builder2.add_edge(START, "blog_agent")
|
| 76 |
+
builder2.add_edge("blog_agent", "seo_keyword")
|
| 77 |
+
builder2.add_edge("seo_keyword", "simple_seo_blog")
|
| 78 |
+
builder2.add_edge("simple_seo_blog", "image_formatted_blog")
|
| 79 |
builder2.add_edge("image_formatted_blog", "image_prompts")
|
| 80 |
builder2.add_edge("image_prompts", END)
|
| 81 |
+
|
| 82 |
graph2 = builder2.compile()
|
| 83 |
|
| 84 |
|
| 85 |
+
# Graph 3:
|
| 86 |
+
builder3 = StateGraph(BlogState)
|
| 87 |
+
|
| 88 |
+
builder3.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
|
| 89 |
+
builder3.add_node("company", lambda state: company_content(llm, state)) #//
|
| 90 |
+
builder3.add_node("market_blog", lambda state: marketed_blog(llm, state)) #//
|
| 91 |
+
builder3.add_node("seo_keyword", lambda state: seo_keywords(state)) # //
|
| 92 |
+
builder3.add_node("market_seo_blog", lambda state: seo_optimized_content_with_marketing(llm, state)) # //
|
| 93 |
+
builder3.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
|
| 94 |
+
builder3.add_node("image_prompts", lambda state: image_prompts(llm, state))
|
| 95 |
+
|
| 96 |
+
builder3.add_edge(START, "blog_agent")
|
| 97 |
+
builder3.add_edge("blog_agent", "company")
|
| 98 |
+
builder3.add_edge("company", "market_blog")
|
| 99 |
+
builder3.add_edge("market_blog", "seo_keyword")
|
| 100 |
+
builder3.add_edge("seo_keyword", "market_seo_blog")
|
| 101 |
+
builder3.add_edge("market_seo_blog", "image_formatted_blog")
|
| 102 |
+
builder3.add_edge("image_formatted_blog", "image_prompts")
|
| 103 |
+
builder3.add_edge("image_prompts", END)
|
| 104 |
+
|
| 105 |
+
graph3 = builder3.compile()
|
| 106 |
+
|
| 107 |
+
|
| 108 |
|
| 109 |
st.title("Generate Latest Information Blog")
|
| 110 |
+
|
| 111 |
input_data = st.text_input("Enter a Category for your blog:")
|
| 112 |
|
| 113 |
if 'titles' not in st.session_state:
|
|
|
|
| 128 |
if st.session_state.titles:
|
| 129 |
st.session_state.selected_title = st.selectbox("Pick the Title for your Blog", st.session_state.titles)
|
| 130 |
|
| 131 |
+
# Checkbox for adding CTAs
|
| 132 |
+
add_cta = st.checkbox("Include Call to Actions")
|
| 133 |
+
|
| 134 |
+
if add_cta:
|
| 135 |
+
# Input fields for website and contact URLs
|
| 136 |
+
website_url = st.text_input("Enter your website URL:")
|
| 137 |
+
contact_url = st.text_input("Enter your contact us URL:")
|
| 138 |
+
|
| 139 |
+
# Generate Blog with CTAs button
|
| 140 |
+
if st.button("Generate Blog with CTAs"):
|
| 141 |
+
try:
|
| 142 |
+
content = graph3.invoke({
|
| 143 |
+
"final_topic": st.session_state.selected_title,
|
| 144 |
+
"url": website_url,
|
| 145 |
+
"contact_us_url": contact_url
|
| 146 |
+
})
|
| 147 |
+
st.markdown(content.get('image_formated_blog', "No content generated.")) # Avoid KeyError
|
| 148 |
+
except Exception as e:
|
| 149 |
+
st.error(str(e))
|
| 150 |
+
else:
|
| 151 |
+
# Generate Blog button without CTAs
|
| 152 |
+
if st.button("Generate Blog"):
|
| 153 |
+
try:
|
| 154 |
+
content = graph2.invoke({"final_topic": st.session_state.selected_title})
|
| 155 |
+
st.markdown(content.get('image_formated_blog', "No content generated.")) # Avoid KeyError
|
| 156 |
+
except Exception as e:
|
| 157 |
+
st.error(str(e))
|
| 158 |
|
|
|