AhsanRazi commited on
Commit
91e8649
·
verified ·
1 Parent(s): 0777aa4

Update pages/Custom.py

Browse files
Files changed (1) hide show
  1. pages/Custom.py +77 -20
pages/Custom.py CHANGED
@@ -7,56 +7,113 @@ import streamlit as st
7
  from langgraph.graph import START, StateGraph, END
8
 
9
  st.set_page_config(
10
- page_title="General Information Blog"
11
  )
12
 
13
  load_dotenv(override=True)
14
  gemini_api_key = os.getenv("GEMINI_API_KEY")
 
15
 
16
 
17
  from blog_content_generator import blog_content_agent
18
  from image_fomatted_blog_generator import image_formatted_blog
19
  from image_prompts_generator import image_prompts
20
 
 
 
 
 
 
 
21
 
22
  llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key) # type:ignore
23
 
24
  class BlogState(TypedDict):
25
  final_topic: str
26
  blog_content: str
 
 
 
 
 
 
27
  image_formated_blog: str
28
  prompts: Dict[str, str]
29
 
30
- # Graph
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
 
33
  # Graph 2:
34
- builder = StateGraph(BlogState)
35
- builder.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
36
- builder.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
37
- builder.add_node("image_prompts", lambda state: image_prompts(llm, state))
38
 
39
- builder.add_edge(START, "blog_agent")
40
- builder.add_edge("blog_agent", "image_formatted_blog")
41
- builder.add_edge("image_formatted_blog", "image_prompts")
42
- builder.add_edge("image_prompts", END)
43
- graph = builder.compile()
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
 
46
 
47
  st.title("Generate Custom Title Blog")
 
48
  input_data = st.text_input("Enter a Title for your blog:")
49
 
50
- if input_data: # Ensure input_data is not empty
51
- if st.button("Generate Blog"):
 
 
 
 
 
 
 
 
52
  try:
53
- content = graph.invoke({"final_topic": input_data})
 
 
 
 
 
54
  st.markdown(content.get('image_formated_blog', "No content generated.")) # Avoid KeyError
55
  except Exception as e:
56
  st.error(str(e))
57
-
58
-
59
-
60
-
61
-
62
-
 
 
 
7
  from langgraph.graph import START, StateGraph, END
8
 
9
  st.set_page_config(
10
+ page_title="Custom Title Blog"
11
  )
12
 
13
  load_dotenv(override=True)
14
  gemini_api_key = os.getenv("GEMINI_API_KEY")
15
+ tavily_api_key = os.getenv("TAVILY_API_KEY")
16
 
17
 
18
  from blog_content_generator import blog_content_agent
19
  from image_fomatted_blog_generator import image_formatted_blog
20
  from image_prompts_generator import image_prompts
21
 
22
+ from company_content_generator import company_content
23
+ from marketed_blog import marketed_blog
24
+ from seo_keywords import seo_keywords
25
+ from seo_optimized_content_generator import seo_optimized_content_with_marketing
26
+ from seo_optimized_content_generator import simple_seo_optimized_content
27
+
28
 
29
  llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key) # type:ignore
30
 
31
  class BlogState(TypedDict):
32
  final_topic: str
33
  blog_content: str
34
+ url: str #//
35
+ contact_us_url: str #//
36
+ company_information: str #//
37
+ company_marketed_blog: str #//
38
+ seo_keywords: str #//
39
+ seo_optimized_blog: str #//
40
  image_formated_blog: str
41
  prompts: Dict[str, str]
42
 
43
+
44
+
45
+ # Graph 1:
46
+ builder1 = StateGraph(BlogState)
47
+
48
+ builder1.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
49
+ builder1.add_node("seo_keyword", lambda state: seo_keywords(state)) # //
50
+ builder1.add_node("simple_seo_blog", lambda state: simple_seo_optimized_content(llm, state)) # //
51
+ builder1.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
52
+ builder1.add_node("image_prompts", lambda state: image_prompts(llm, state))
53
+
54
+ builder1.add_edge(START, "blog_agent")
55
+ builder1.add_edge("blog_agent", "seo_keyword")
56
+ builder1.add_edge("seo_keyword", "simple_seo_blog")
57
+ builder1.add_edge("simple_seo_blog", "image_formatted_blog")
58
+ builder1.add_edge("image_formatted_blog", "image_prompts")
59
+ builder1.add_edge("image_prompts", END)
60
+
61
+ graph1 = builder1.compile()
62
 
63
 
64
  # Graph 2:
65
+ builder2 = StateGraph(BlogState)
 
 
 
66
 
67
+ builder2.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
68
+ builder2.add_node("company", lambda state: company_content(llm, state)) #//
69
+ builder2.add_node("market_blog", lambda state: marketed_blog(llm, state)) #//
70
+ builder2.add_node("seo_keyword", lambda state: seo_keywords(state)) # //
71
+ builder2.add_node("market_seo_blog", lambda state: seo_optimized_content_with_marketing(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", "company")
77
+ builder2.add_edge("company", "market_blog")
78
+ builder2.add_edge("market_blog", "seo_keyword")
79
+ builder2.add_edge("seo_keyword", "market_seo_blog")
80
+ builder2.add_edge("market_seo_blog", "image_formatted_blog")
81
+ builder2.add_edge("image_formatted_blog", "image_prompts")
82
+ builder2.add_edge("image_prompts", END)
83
+
84
+ graph2 = builder2.compile()
85
 
86
 
87
 
88
  st.title("Generate Custom Title Blog")
89
+
90
  input_data = st.text_input("Enter a Title for your blog:")
91
 
92
+ # Checkbox for adding CTAs
93
+ add_cta = st.checkbox("Include Call to Actions")
94
+
95
+ if add_cta:
96
+ # Input fields for website and contact URLs
97
+ website_url = st.text_input("Enter your website URL:")
98
+ contact_url = st.text_input("Enter your contact us URL:")
99
+
100
+ # Generate Blog button with CTAs
101
+ if st.button("Generate Blog with CTAs"):
102
  try:
103
+ # Assuming graph.invoke accepts a dictionary with additional CTA fields
104
+ content = graph2.invoke({
105
+ "final_topic": input_data,
106
+ "url": website_url,
107
+ "contact_us_url": contact_url
108
+ })
109
  st.markdown(content.get('image_formated_blog', "No content generated.")) # Avoid KeyError
110
  except Exception as e:
111
  st.error(str(e))
112
+ else:
113
+ # Generate Blog button without CTAs
114
+ if st.button("Generate Blog"):
115
+ try:
116
+ content = graph1.invoke({"final_topic": input_data})
117
+ st.markdown(content.get('image_formated_blog', "No content generated.")) # Avoid KeyError
118
+ except Exception as e:
119
+ st.error(str(e))