AhsanRazi commited on
Commit
1170833
·
verified ·
1 Parent(s): beaa0d6

Update pages/Custom.py

Browse files
Files changed (1) hide show
  1. pages/Custom.py +59 -0
pages/Custom.py CHANGED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from langchain_google_genai import ChatGoogleGenerativeAI
3
+ from typing import List, Dict
4
+ from typing_extensions import TypedDict
5
+ from dotenv import load_dotenv
6
+ 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
+
51
+ if st.button("Generate Blog"):
52
+ content = graph.invoke({"final_topic": input_data})
53
+ st.markdown(content['image_formated_blog'])
54
+
55
+
56
+
57
+
58
+
59
+