File size: 5,695 Bytes
0424771
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee26fcb
 
 
 
 
 
0424771
 
 
 
 
 
 
 
 
 
 
 
ee26fcb
 
 
 
 
 
0424771
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee26fcb
 
0424771
 
 
 
ee26fcb
 
 
0424771
 
ee26fcb
0424771
 
 
ee26fcb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0424771
 
ee26fcb
0424771
 
 
 
 
 
 
3f61da5
 
 
 
 
 
 
 
 
 
 
 
 
ee26fcb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0424771
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import os
import streamlit as st
from typing import List, Dict
from dotenv import load_dotenv
from typing_extensions import TypedDict
from langchain_core.messages import HumanMessage
from langgraph.graph import START, StateGraph, END
from langchain_google_genai import ChatGoogleGenerativeAI

# General Information Blog
st.set_page_config(
    page_title="Latest Information Blog"
)

# Secret Key
load_dotenv(override=True)
gemini_api_key = os.getenv("GEMINI_API_KEY")


# Latest Information Blog
from search_queries_generator import generate_queries
from blog_title_generator import blog_titles_agent
from blog_content_generator import blog_content_agent
from image_fomatted_blog_generator import image_formatted_blog
from image_prompts_generator import image_prompts

from company_content_generator import company_content
from marketed_blog import marketed_blog
from seo_keywords import seo_keywords
from seo_optimized_content_generator import seo_optimized_content_with_marketing
from seo_optimized_content_generator import simple_seo_optimized_content


# LLM
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key) # type:ignore


# Define State
class BlogState(TypedDict):
    topic: str
    search_queries: List[str]
    blog_topics: List[str]     
    final_topic: str
    blog_content: str
    url: str #//
    contact_us_url: str #//
    company_information: str #//
    company_marketed_blog: str #//
    seo_keywords: str #//
    seo_optimized_blog: str #//
    image_formated_blog: str  
    prompts: Dict[str, str]

    


# Graph 1: 
builder1 = StateGraph(BlogState)
builder1.add_node("queries", lambda state: generate_queries(llm, state))
builder1.add_node("blog_topic", lambda state: blog_titles_agent(llm, state))

builder1.add_edge(START, "queries")
builder1.add_edge("queries", "blog_topic")
builder1.add_edge("blog_topic", END)
graph1 = builder1.compile()

# Graph 2: 
builder2 = StateGraph(BlogState)
builder2.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
builder2.add_node("seo_keyword", lambda state: seo_keywords(state)) # //
builder2.add_node("simple_seo_blog", lambda state: simple_seo_optimized_content(llm, state)) # //
builder2.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
builder2.add_node("image_prompts", lambda state: image_prompts(llm, state))

builder2.add_edge(START, "blog_agent")
builder2.add_edge("blog_agent", "seo_keyword")
builder2.add_edge("seo_keyword", "simple_seo_blog")
builder2.add_edge("simple_seo_blog", "image_formatted_blog")
builder2.add_edge("image_formatted_blog", "image_prompts")
builder2.add_edge("image_prompts", END)

graph2 = builder2.compile()


# Graph 3: 
builder3 = StateGraph(BlogState)

builder3.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
builder3.add_node("company", lambda state: company_content(llm, state)) #//
builder3.add_node("market_blog", lambda state: marketed_blog(llm, state)) #//
builder3.add_node("seo_keyword", lambda state: seo_keywords(state)) # //
builder3.add_node("market_seo_blog", lambda state: seo_optimized_content_with_marketing(llm, state)) # //
builder3.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
builder3.add_node("image_prompts", lambda state: image_prompts(llm, state))

builder3.add_edge(START, "blog_agent")
builder3.add_edge("blog_agent", "company")
builder3.add_edge("company", "market_blog")
builder3.add_edge("market_blog", "seo_keyword")
builder3.add_edge("seo_keyword", "market_seo_blog")
builder3.add_edge("market_seo_blog", "image_formatted_blog")
builder3.add_edge("image_formatted_blog", "image_prompts")
builder3.add_edge("image_prompts", END)

graph3 = builder3.compile()



st.title("Generate Latest Information Blog")

input_data = st.text_input("Enter a Category for your blog:")

if 'titles' not in st.session_state:
    st.session_state.titles = None
if 'selected_title' not in st.session_state:
    st.session_state.selected_title = None

if input_data:  # Only proceed if input_data is not empty
    if st.button("Generate Titles"):
        try:
            topic = [HumanMessage(content=input_data)]
            result = graph1.invoke({"topic": topic})
            print(result)
            st.session_state.titles = result.get('blog_topics', [])  # Avoid KeyError
        except Exception as e:
            st.error(str(e))

if st.session_state.titles:
    st.session_state.selected_title = st.selectbox("Pick the Title for your Blog", st.session_state.titles)

    # Checkbox for adding CTAs
    add_cta = st.checkbox("Include Call to Actions")

    if add_cta:
        # Input fields for website and contact URLs
        website_url = st.text_input("Enter your website URL:")
        contact_url = st.text_input("Enter your contact us URL:")

        # Generate Blog with CTAs button
        if st.button("Generate Blog with CTAs"):
            try:
                content = graph3.invoke({
                    "final_topic": st.session_state.selected_title,
                    "url": website_url,
                    "contact_us_url": contact_url
                })
                st.markdown(content.get('image_formated_blog', "No content generated."))  # Avoid KeyError
            except Exception as e:
                st.error(str(e))
    else:
        # Generate Blog button without CTAs
        if st.button("Generate Blog"):
            try:
                content = graph2.invoke({"final_topic": st.session_state.selected_title})
                st.markdown(content.get('image_formated_blog', "No content generated."))  # Avoid KeyError
            except Exception as e:
                st.error(str(e))