Update app.py
Browse files
app.py
CHANGED
@@ -89,51 +89,54 @@ def generate_response(topic, length):
|
|
89 |
|
90 |
return app.invoke(input={"topic": topic, "length": length})
|
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 |
-
|
120 |
-
|
121 |
-
|
122 |
-
st.markdown(
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
137 |
with tab2:
|
138 |
st.subheader("📊 Multi-Agent Workflow Visualization")
|
139 |
|
@@ -160,4 +163,4 @@ st.markdown(
|
|
160 |
</div>
|
161 |
""",
|
162 |
unsafe_allow_html=True,
|
163 |
-
|
|
|
89 |
|
90 |
return app.invoke(input={"topic": topic, "length": length})
|
91 |
|
92 |
+
# Define Tabs
|
93 |
+
tab1, tab2 = st.tabs(["📜 Essay Generation", "📊 Workflow Visualization"])
|
94 |
+
|
95 |
+
# 📜 Tab 1: Essay Generation
|
96 |
+
with tab1:
|
97 |
+
st.subheader("📝 Generate an Essay")
|
98 |
+
|
99 |
+
# Display chat messages from the session
|
100 |
+
if "messages" in st.session_state:
|
101 |
+
for message in st.session_state["messages"]:
|
102 |
+
with st.chat_message(message["role"]):
|
103 |
+
st.markdown(message["content"], unsafe_allow_html=True)
|
104 |
+
|
105 |
+
# Handle user input
|
106 |
+
if topic := st.chat_input(placeholder="📝 Ask a question or provide an essay topic...", disabled=st.session_state["chat_active"]):
|
107 |
+
st.chat_message("user").markdown(topic)
|
108 |
+
st.session_state["messages"].append({"role": "user", "content": topic})
|
109 |
+
|
110 |
+
with st.spinner("⏳ Generating your essay..."):
|
111 |
+
response = generate_response(topic, essay_length)
|
112 |
+
|
113 |
+
# Handle the assistant's response
|
114 |
+
with st.chat_message("assistant"):
|
115 |
+
if "essay" in response: # Display essay preview and download link
|
116 |
+
st.markdown(f"### 📝 Essay Preview ({essay_length} words)")
|
117 |
+
st.markdown(f"#### {response['essay']['header']}")
|
118 |
+
st.markdown(response["essay"]["entry"])
|
119 |
+
for para in response["essay"]["paragraphs"]:
|
120 |
+
st.markdown(f"**{para['sub_header']}**")
|
121 |
+
st.markdown(para["paragraph"])
|
122 |
+
st.markdown("**🖊️ Conclusion:**")
|
123 |
+
st.markdown(response["essay"]["conclusion"])
|
124 |
+
|
125 |
+
# Provide download link for the PDF
|
126 |
+
with open(response["pdf_name"], "rb") as pdf_file:
|
127 |
+
b64 = base64.b64encode(pdf_file.read()).decode()
|
128 |
+
href = f"<a href='data:application/octet-stream;base64,{b64}' download='{response['pdf_name']}'>📄 Click here to download the PDF</a>"
|
129 |
+
st.markdown(href, unsafe_allow_html=True)
|
130 |
+
|
131 |
+
# Save the assistant's message to session state
|
132 |
+
st.session_state["messages"].append(
|
133 |
+
{"role": "assistant", "content": f"Here is your {essay_length}-word essay preview and the download link."}
|
134 |
+
)
|
135 |
+
else: # For other responses (e.g., general answers)
|
136 |
+
st.markdown(response["response"])
|
137 |
+
st.session_state["messages"].append({"role": "assistant", "content": response["response"]})
|
138 |
+
|
139 |
+
# 📊 Tab 2: Workflow Visualization
|
140 |
with tab2:
|
141 |
st.subheader("📊 Multi-Agent Workflow Visualization")
|
142 |
|
|
|
163 |
</div>
|
164 |
""",
|
165 |
unsafe_allow_html=True,
|
166 |
+
)
|