Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
-
from graph import EssayWriter
|
3 |
import os
|
4 |
import base64
|
5 |
|
6 |
st.set_page_config(page_title="Multi-Agent Essay Writer", page_icon="🤖🤖🤖✍️")
|
7 |
|
8 |
-
# Button HTML
|
9 |
button_html = f'''
|
10 |
<div style="display: flex; justify-content: center;">
|
11 |
<a href=" " target="_blank">
|
@@ -41,7 +41,7 @@ with st.sidebar:
|
|
41 |
"\n\n* This app uses the 'gpt-4o-mini-2024-07-18' model."
|
42 |
"\n\n* Writing essays may take some time, approximately 1-2 minutes."
|
43 |
)
|
44 |
-
|
45 |
openai_key = st.secrets.get("OPENAI_API_KEY", "")
|
46 |
|
47 |
st.divider()
|
@@ -66,8 +66,8 @@ def initialize_agents():
|
|
66 |
return st.session_state.app # Prevent re-initialization
|
67 |
|
68 |
essay_writer = EssayWriter().graph
|
69 |
-
st.success("Agents successfully initialized!")
|
70 |
st.session_state.chat_active = False
|
|
|
71 |
return essay_writer
|
72 |
except Exception as e:
|
73 |
st.error(f"Error initializing agents: {e}")
|
@@ -78,11 +78,18 @@ def initialize_agents():
|
|
78 |
if "app" not in st.session_state or st.session_state.app is None:
|
79 |
st.session_state.app = initialize_agents()
|
80 |
|
|
|
|
|
|
|
81 |
app = st.session_state.app
|
82 |
|
83 |
# Function to invoke the agent and generate a response
|
84 |
def generate_response(topic):
|
85 |
-
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# Display chat messages from the session
|
88 |
for message in st.session_state.messages:
|
|
|
1 |
import streamlit as st
|
2 |
+
from graph import EssayWriter
|
3 |
import os
|
4 |
import base64
|
5 |
|
6 |
st.set_page_config(page_title="Multi-Agent Essay Writer", page_icon="🤖🤖🤖✍️")
|
7 |
|
8 |
+
# Button HTML (for external links)
|
9 |
button_html = f'''
|
10 |
<div style="display: flex; justify-content: center;">
|
11 |
<a href=" " target="_blank">
|
|
|
41 |
"\n\n* This app uses the 'gpt-4o-mini-2024-07-18' model."
|
42 |
"\n\n* Writing essays may take some time, approximately 1-2 minutes."
|
43 |
)
|
44 |
+
|
45 |
openai_key = st.secrets.get("OPENAI_API_KEY", "")
|
46 |
|
47 |
st.divider()
|
|
|
66 |
return st.session_state.app # Prevent re-initialization
|
67 |
|
68 |
essay_writer = EssayWriter().graph
|
|
|
69 |
st.session_state.chat_active = False
|
70 |
+
st.success("Agents successfully initialized!")
|
71 |
return essay_writer
|
72 |
except Exception as e:
|
73 |
st.error(f"Error initializing agents: {e}")
|
|
|
78 |
if "app" not in st.session_state or st.session_state.app is None:
|
79 |
st.session_state.app = initialize_agents()
|
80 |
|
81 |
+
if st.session_state.app is None:
|
82 |
+
st.error("Failed to initialize agents. Please check your API key and restart the app.")
|
83 |
+
|
84 |
app = st.session_state.app
|
85 |
|
86 |
# Function to invoke the agent and generate a response
|
87 |
def generate_response(topic):
|
88 |
+
if not app:
|
89 |
+
st.error("Agents are not initialized. Please check the system or restart the app.")
|
90 |
+
return {"response": "Error: Agents not initialized."}
|
91 |
+
|
92 |
+
return app.invoke(input={"topic": topic})
|
93 |
|
94 |
# Display chat messages from the session
|
95 |
for message in st.session_state.messages:
|