Spaces:
Runtime error
Runtime error
import streamlit as st | |
from streamlit import session_state as ss | |
import db_utils | |
from pg_agents import PageAgents | |
from pg_tasks import PageTasks | |
from pg_crews import PageCrews | |
from pg_tools import PageTools | |
from pg_crew_run import PageCrewRun | |
from pg_export_crew import PageExportCrew | |
from dotenv import load_dotenv | |
import os | |
def pages(): | |
return { | |
'Crews': PageCrews(), | |
'Tools': PageTools(), | |
'Agents': PageAgents(), | |
'Tasks': PageTasks(), | |
'Kickoff!': PageCrewRun(), | |
'Import/export': PageExportCrew() | |
} | |
def load_data(): | |
ss.agents = db_utils.load_agents() | |
ss.tasks = db_utils.load_tasks() | |
ss.crews = db_utils.load_crews() | |
ss.tools = db_utils.load_tools() | |
ss.enabled_tools = db_utils.load_tools_state() | |
def draw_sidebar(): | |
with st.sidebar: | |
st.image("img/crewai_logo.png") | |
if 'page' not in ss: | |
ss.page = 'Crews' | |
selected_page = st.radio('Page', list(pages().keys()), index=list(pages().keys()).index(ss.page),label_visibility="collapsed") | |
if selected_page != ss.page: | |
ss.page = selected_page | |
st.rerun() | |
def main(): | |
st.set_page_config(page_title="CrewAI Studio", page_icon="img/favicon.ico", layout="wide") | |
load_dotenv() | |
if (str(os.getenv('AGENTOPS_ENABLED')).lower() in ['true', '1']) and not ss.get('agentops_failed', False): | |
try: | |
import agentops | |
agentops.init(api_key=os.getenv('AGENTOPS_API_KEY'),auto_start_session=False) | |
except ModuleNotFoundError as e: | |
ss.agentops_failed = True | |
print(f"Error initializing AgentOps: {str(e)}") | |
db_utils.initialize_db() | |
load_data() | |
draw_sidebar() | |
PageCrewRun.maintain_session_state() #this will persist the session state for the crew run page so crew run can be run in a separate thread | |
pages()[ss.page].draw() | |
if __name__ == '__main__': | |
main() | |