msaifee commited on
Commit
1f64690
Β·
1 Parent(s): 5631744

Refined flows

Browse files
Files changed (1) hide show
  1. app.py +68 -39
app.py CHANGED
@@ -7,6 +7,7 @@ from langgraph.graph import add_messages, StateGraph, END, START
7
  from langchain_core.messages import AIMessage, HumanMessage
8
  from typing import Annotated, List
9
 
 
10
  # Load environment variables
11
  load_dotenv()
12
 
@@ -27,6 +28,8 @@ if 'blog_state' not in st.session_state:
27
  st.session_state.blog_state = None
28
  if 'graph' not in st.session_state:
29
  st.session_state.graph = None
 
 
30
 
31
  def init_graph():
32
  builder = StateGraph(BlogState)
@@ -114,49 +117,75 @@ def route_based_on_verdict(state: BlogState):
114
  return "Pass" if state["is_blog_ready"] == "Pass" else "Fail"
115
 
116
  # Streamlit UI components
117
- st.title("AI Blog Generation Assistant")
118
- st.markdown("### Generate high-quality blog posts with AI-powered review process")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
 
 
120
  topic = st.text_input("Enter your blog topic:", placeholder="Generative AI in Healthcare")
121
  generate_btn = st.button("Generate Blog Post")
122
 
123
-
124
- if generate_btn and topic:
125
- st.session_state.graph = init_graph()
126
- st.session_state.blog_state = BlogState(
127
- topic=topic,
128
- title="",
129
- blog_content=[],
130
- reviewed_content=[],
131
- is_blog_ready=""
132
- )
133
-
134
- # Execute the graph
135
- final_state = st.session_state.graph.invoke(st.session_state.blog_state)
136
- st.session_state.blog_state = final_state
137
-
138
- # Display results
139
- st.success("Blog post generation complete!")
140
- st.markdown("---")
141
- st.subheader("Final Blog Post")
142
- st.markdown(final_state["blog_content"][-1].content)
143
 
144
- st.markdown("---")
145
- st.subheader("Quality Assurance Report")
146
- st.write(final_state["reviewed_content"][-1].content)
147
- # st.write(f"Final Verdict: {final_state['is_blog_ready']}")
148
 
149
-
150
- elif generate_btn and not topic:
151
- st.error("Please enter a blog topic to get started!")
152
-
153
- if st.session_state.blog_state:
154
- with st.sidebar:
155
- st.subheader("Generation Details")
156
- st.write(f"**Topic:** {st.session_state.blog_state['topic']}")
157
- st.write(f"**Status**: {'βœ… Approved' if st.session_state.blog_state['is_blog_ready'] == 'Pass' else '❌ Needs Revision'}")
158
- st.write(f"**Review Cycles**: {len(st.session_state.blog_state['reviewed_content']) - 1}")
159
 
160
- if st.button("Reset Session"):
161
- st.session_state.clear()
162
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  from langchain_core.messages import AIMessage, HumanMessage
8
  from typing import Annotated, List
9
 
10
+
11
  # Load environment variables
12
  load_dotenv()
13
 
 
28
  st.session_state.blog_state = None
29
  if 'graph' not in st.session_state:
30
  st.session_state.graph = None
31
+ if 'graph_image' not in st.session_state:
32
+ st.session_state.graph_image = None
33
 
34
  def init_graph():
35
  builder = StateGraph(BlogState)
 
117
  return "Pass" if state["is_blog_ready"] == "Pass" else "Fail"
118
 
119
  # Streamlit UI components
120
+ st.title("πŸš€ BlogForge Pro")
121
+ st.markdown("""
122
+ **Smart Blog Generation with Auto-Refinement**
123
+ *From first draft to final edit - AI-assisted writing meets professional standards*
124
+ βœ“ SEO-Optimized Structure βœ“ Grammar & Style Checks βœ“ Feedback-Driven Revisions
125
+ """)
126
+
127
+ # Sidebar components
128
+ def show_sidebar():
129
+
130
+ with st.sidebar:
131
+ st.subheader("Configuration")
132
+
133
+ # Groq API Key Input
134
+ api_key = st.session_state["GROQ_API_KEY"] = st.text_input("Groq API Key",type="password")
135
+ # Validate API key
136
+ if not api_key:
137
+ st.warning("⚠️ Please enter your GROQ API key to proceed. Don't have? refer : https://console.groq.com/keys ")
138
+
139
+
140
+ if st.button("Reset Session"):
141
+ st.session_state.clear()
142
+ st.rerun()
143
 
144
+ show_sidebar()
145
+ # Main content
146
  topic = st.text_input("Enter your blog topic:", placeholder="Generative AI in Healthcare")
147
  generate_btn = st.button("Generate Blog Post")
148
 
149
+ if generate_btn:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
+ if not topic:
152
+ st.error("Please enter a blog topic!")
153
+ st.stop()
 
154
 
155
+ try:
156
+ st.session_state.llm = ChatGroq(model="qwen-2.5-32b")
 
 
 
 
 
 
 
 
157
 
158
+ # Initialize and run graph
159
+ st.session_state.graph = init_graph()
160
+ st.session_state.blog_state = BlogState(
161
+ topic=topic,
162
+ title="",
163
+ blog_content=[],
164
+ reviewed_content=[],
165
+ is_blog_ready=""
166
+ )
167
+
168
+ # Execute the graph
169
+ final_state = st.session_state.graph.invoke(st.session_state.blog_state)
170
+ st.session_state.blog_state = final_state
171
+
172
+
173
+ # Display results
174
+ st.success("Blog post generation complete!")
175
+ st.markdown("---")
176
+ st.subheader("Final Blog Post")
177
+ st.markdown(final_state["blog_content"][-1].content)
178
+
179
+ st.markdown("---")
180
+ st.subheader("Quality Assurance Report")
181
+ st.write(final_state["reviewed_content"][-1].content)
182
+
183
+ if st.session_state.blog_state:
184
+ st.markdown("---")
185
+ st.subheader("Generation Status")
186
+ st.write(f"**Topic:** {st.session_state.blog_state['topic']}")
187
+ st.write(f"**Status**: {'βœ… Approved' if st.session_state.blog_state['is_blog_ready'] == 'Pass' else '❌ Needs Revision'}")
188
+ st.write(f"**Review Cycles**: {len(st.session_state.blog_state['reviewed_content']) - 1}")
189
+
190
+ except Exception as e:
191
+ st.error(f"Error in blog generation: {str(e)}")