AhsanRazi commited on
Commit
253efeb
·
verified ·
1 Parent(s): 48c1682

Delete Latest.py

Browse files
Files changed (1) hide show
  1. Latest.py +0 -95
Latest.py DELETED
@@ -1,95 +0,0 @@
1
- import os
2
- import streamlit as st
3
- from typing import List, Dict
4
- from dotenv import load_dotenv
5
- from typing_extensions import TypedDict
6
- from langchain_core.messages import HumanMessage
7
- from langgraph.graph import START, StateGraph, END
8
- from langchain_google_genai import ChatGoogleGenerativeAI
9
-
10
- # General Information Blog
11
- st.set_page_config(
12
- page_title="Latest Information Blog"
13
- )
14
-
15
- # Secret Key
16
- load_dotenv(override=True)
17
- gemini_api_key = os.getenv("GEMINI_API_KEY")
18
-
19
-
20
-
21
- # Latest Information Blog
22
- from markdown import to_markdown
23
- from search_queries_generator import generate_queries
24
- from blog_title_generator import blog_titles_agent
25
- from blog_content_generator import blog_content_agent
26
- from image_fomatted_blog_generator import image_formatted_blog
27
- from image_prompts_generator import image_prompts
28
-
29
-
30
- # LLM
31
- llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key) # type:ignore
32
-
33
-
34
- # Define State
35
- class BlogState(TypedDict):
36
- topic: str
37
- search_queries: List[str]
38
- blog_topics: List[str]
39
- final_topic: str
40
- blog_content: str
41
- image_formated_blog: str
42
- prompts: Dict[str, str]
43
-
44
-
45
-
46
-
47
- # Graph 1:
48
- builder1 = StateGraph(BlogState)
49
- builder1.add_node("queries", lambda state: generate_queries(llm, state))
50
- builder1.add_node("blog_topic", lambda state: blog_titles_agent(llm, state))
51
-
52
- builder1.add_edge(START, "queries")
53
- builder1.add_edge("queries", "blog_topic")
54
- builder1.add_edge("blog_topic", END)
55
- graph1 = builder1.compile()
56
-
57
- # Graph 2:
58
- builder2 = StateGraph(BlogState)
59
- builder2.add_node("blog_agent", lambda state: blog_content_agent(llm, state))
60
- builder2.add_node("image_formatted_blog", lambda state: image_formatted_blog(llm, state))
61
- builder2.add_node("image_prompts", lambda state: image_prompts(llm, state))
62
-
63
- builder2.add_edge(START, "blog_agent")
64
- builder2.add_edge("blog_agent", "image_formatted_blog")
65
- builder2.add_edge("image_formatted_blog", "image_prompts")
66
- builder2.add_edge("image_prompts", END)
67
- graph2 = builder2.compile()
68
-
69
-
70
-
71
- st.title("Generate Latest Information Blog")
72
- input_data = st.text_input("Enter a Category for your blog:")
73
-
74
- if 'titles' not in st.session_state:
75
- st.session_state.titles = None
76
- if 'selected_title' not in st.session_state:
77
- st.session_state.selected_title = None
78
-
79
- if st.button("Generate Titles"):
80
- try:
81
- topic = [HumanMessage(content=input_data)]
82
- result = graph1.invoke({"topic": topic})
83
- print(result)
84
- st.session_state.titles = result['blog_topics']
85
- except Exception as e:
86
- st.error(str(e))
87
-
88
- if st.session_state.titles is not None:
89
- st.session_state.selected_title = st.selectbox("Pick the Title for your Blog", st.session_state.titles)
90
-
91
- if st.button("Generate Blog") and st.session_state.selected_title is not None:
92
- content = graph2.invoke({"final_topic": st.session_state.selected_title})
93
- st.markdown(content['image_formated_blog'])
94
-
95
-