import os import streamlit as st from lib.utils.file_processor import load_image from lib.utils.content_generators import content_planning_tools from lib.utils.alwrity_utils import ai_social_writer from lib.utils.seo_tools import ai_seo_tools from lib.utils.settings_page import render_settings_page from loguru import logger # Import social media writer functions from lib.ai_writers.ai_facebook_writer.facebook_ai_writer import facebook_main_menu from lib.ai_writers.linkedin_writer.linkedin_ai_writer import linkedin_main_menu from lib.ai_writers.twitter_writers import run_dashboard from lib.ai_writers.insta_ai_writer import insta_writer from lib.ai_writers.youtube_writers.youtube_ai_writer import youtube_main_menu from lib.ai_writers.ai_writer_dashboard import get_ai_writers, list_ai_writers def setup_ui(): """Set up the UI with custom styling.""" # Add custom CSS st.markdown(""" """, unsafe_allow_html=True) def setup_alwrity_ui(): """Sets up the main navigation in the sidebar.""" logger.info("Setting up ALwrity UI") # Initialize session state for active tab if not exists if 'active_tab' not in st.session_state: st.session_state.active_tab = "Content Planning" logger.info(f"Initialized active_tab to: {st.session_state.active_tab}") # Initialize session state for active sub-tab if not exists if 'active_sub_tab' not in st.session_state: st.session_state.active_sub_tab = None logger.info("Initialized active_sub_tab to None") # Define the navigation items with their icons and functions nav_items = { "AI Writers": ("📝", get_ai_writers), "Content Planning": ("📅", content_planning_tools), "AI SEO Tools": ("🔍", ai_seo_tools), "AI Social Tools": ("📱", None), # Set to None as we'll handle this separately "Agents Teams(TBD)": ("🤝", lambda: st.subheader("Agents Teams - Coming Soon!")), "Ask Alwrity(TBD)": ("💬", lambda: ( st.subheader("Chat with your Data, Chat with any Data.. COMING SOON !"), st.markdown("Create a collection by uploading files (PDF, MD, CSV, etc), or crawl a data source (Websites, more sources coming soon."), st.markdown("One can ask/chat, summarize and do semantic search over the uploaded data") )), "ALwrity Settings": ("⚙️", render_settings_page) } logger.info(f"Defined {len(nav_items)} navigation items") # Define sub-menu items for AI Social Tools social_tools_submenu = { "Facebook": ("📘", lambda: facebook_main_menu()), "LinkedIn": ("💼", lambda: linkedin_main_menu()), "Twitter": ("🐦", lambda: run_dashboard()), "Instagram": ("📸", lambda: insta_writer()), "YouTube": ("🎥", lambda: youtube_main_menu()) } logger.info(f"Defined {len(social_tools_submenu)} social tools submenu items") # Create sidebar navigation st.sidebar.markdown("### ALwrity Options") st.sidebar.markdown('
', unsafe_allow_html=True) # Add the AskAlwrity icon at the bottom of sidebar st.sidebar.markdown('', unsafe_allow_html=True) # Display content based on active tab if st.session_state.active_tab == "AI Social Tools": if not st.session_state.active_sub_tab: # Only show title and info when no sub-tab is selected st.markdown(""" """, unsafe_allow_html=True) st.title(f"{nav_items[st.session_state.active_tab][0]} {st.session_state.active_tab}") st.info("Please select a social media platform from the sidebar.") else: # When a platform is selected, show no title and minimize spacing st.markdown(""" """, unsafe_allow_html=True) # Call the function directly without any title social_tools_submenu[st.session_state.active_sub_tab][1]() else: # Check if we're in the AI Writers section and handle writer selection if st.session_state.active_tab == "AI Writers": # Get the writer parameter from the URL using st.query_params writer = st.query_params.get("writer") logger.info(f"Current writer from query params: {writer}") if writer: # Get the list of writers without rendering the dashboard writers = list_ai_writers() logger.info(f"Found {len(writers)} writers") writer_found = False for w in writers: logger.info(f"Checking writer: {w['name']} with path: {w['path']}") if w["path"] == writer: writer_found = True logger.info(f"Found matching writer: {w['name']}, executing function") # Clear any existing content st.empty() # Execute the writer function w["function"]() break if not writer_found: logger.error(f"No writer found with path: {writer}") st.error(f"No writer found with path: {writer}") else: # If no writer selected, show the dashboard logger.info("No writer selected, showing dashboard") get_ai_writers() else: # For all other tabs, show the title st.markdown(""" """, unsafe_allow_html=True) st.title(f"{nav_items[st.session_state.active_tab][0]} {st.session_state.active_tab}") nav_items[st.session_state.active_tab][1]() logger.info("Finished setting up ALwrity UI")