File size: 4,325 Bytes
1170833
 
 
 
 
 
 
 
 
91e8649
1170833
 
 
 
91e8649
1170833
 
 
 
 
 
91e8649
 
 
 
 
 
1170833
 
 
 
 
 
91e8649
 
 
 
 
 
1170833
 
 
91e8649
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1170833
 
 
91e8649
1170833
91e8649
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1170833
 
 
 
91e8649
1170833
 
91e8649
 
 
 
 
 
 
 
 
 
3b5eec4
91e8649
 
 
 
 
 
3b5eec4
 
 
91e8649
 
 
 
 
 
 
 
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
import os
from langchain_google_genai import ChatGoogleGenerativeAI
from typing import List, Dict
from typing_extensions import TypedDict
from dotenv import load_dotenv
import streamlit as st
from langgraph.graph import START, StateGraph, END

st.set_page_config(
    page_title="Custom Title Blog"
)

load_dotenv(override=True)
gemini_api_key = os.getenv("GEMINI_API_KEY")
tavily_api_key = os.getenv("TAVILY_API_KEY")


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 = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key) # type:ignore

class BlogState(TypedDict):   
    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("blog_agent", lambda state: blog_content_agent(llm, state))
builder1.add_node("seo_keyword", lambda state: seo_keywords(state)) # //
builder1.add_node("simple_seo_blog", lambda state: simple_seo_optimized_content(llm, state)) # //
builder1.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
builder1.add_node("image_prompts", lambda state: image_prompts(llm, state))

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

graph1 = builder1.compile()


# Graph 2: 
builder2 = StateGraph(BlogState)

builder2.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
builder2.add_node("company", lambda state: company_content(llm, state)) #//
builder2.add_node("market_blog", lambda state: marketed_blog(llm, state)) #//
builder2.add_node("seo_keyword", lambda state: seo_keywords(state)) # //
builder2.add_node("market_seo_blog", lambda state: seo_optimized_content_with_marketing(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", "company")
builder2.add_edge("company", "market_blog")
builder2.add_edge("market_blog", "seo_keyword")
builder2.add_edge("seo_keyword", "market_seo_blog")
builder2.add_edge("market_seo_blog", "image_formatted_blog")
builder2.add_edge("image_formatted_blog", "image_prompts")
builder2.add_edge("image_prompts", END)

graph2 = builder2.compile()



st.title("Generate Custom Title Blog")

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

# 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 button with CTAs
    if st.button("Generate Blog with CTAs"):
        try:
            # Assuming graph.invoke accepts a dictionary with additional CTA fields
            content = graph2.invoke({
                "final_topic": input_data,
                "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 = graph1.invoke({"final_topic": input_data})
            st.markdown(content.get('image_formated_blog', "No content generated."))  # Avoid KeyError
        except Exception as e:
            st.error(str(e))