"""Test configuration settings page for ALwrity."""
import streamlit as st
from loguru import logger
import asyncio
from lib.web_crawlers.async_web_crawler import AsyncWebCrawlerService
from pages.style_utils import (
get_test_config_styles,
get_glass_container,
get_info_section,
get_example_box,
get_analysis_section,
get_style_guide_html
)
import sys
from lib.personalization.style_analyzer import StyleAnalyzer
# Set page config - must be the first Streamlit command
st.set_page_config(
layout="wide",
initial_sidebar_state="collapsed",
menu_items={
'Get Help': None,
'Report a bug': None,
'About': None
}
)
import yaml
from pathlib import Path
import os
from loguru import logger
from lib.utils.read_main_config_params import get_personalization_settings
from lib.web_crawlers.crawl4ai_web_crawler import analyze_style
# Configure logger
logger.remove() # Remove default handler
logger.add(
"logs/test_config_settings.log",
rotation="500 MB",
retention="10 days",
level="DEBUG",
format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {message}",
backtrace=True,
diagnose=True
)
logger.add(
sys.stdout,
level="INFO",
format="
Enter a website URL or provide content samples to analyze your writing style and get personalized recommendations.
" ), unsafe_allow_html=True) # Create two columns for the layout col1, col2 = st.columns([2, 1]) with col1: # Website URL input st.markdown("### Website URL") url = st.text_input( "Enter your website URL", placeholder="https://example.com", help="Provide your website URL to analyze your content style. Leave empty if you want to provide written samples instead." ) logger.debug(f"Website URL input value: {url}") # Alternative: Written samples if not url: st.markdown("### Written Samples") st.markdown(get_info_section("""No website URL? No problem! You can provide written samples of your content instead.
Share your best articles, blog posts, or any content that represents your writing style.
"""), unsafe_allow_html=True) samples = st.text_area( "Paste your content samples here", help="Paste 2-3 samples of your best content. This helps ALwrity understand your writing style." ) logger.debug(f"Sample text length: {len(samples) if samples else 0}") st.markdown('', unsafe_allow_html=True) # ALwrity Style button st.markdown("", unsafe_allow_html=True) if st.button("🎨 ALwrity Style", use_container_width=True): if url: with st.status("Starting style analysis...", expanded=True) as status: try: logger.info(f"Starting style analysis for URL: {url}") # Step 1: Initialize crawler status.update(label="Step 1/4: Initializing web crawler...", state="running") crawler_service = AsyncWebCrawlerService() # Step 2: Crawl website status.update(label="Step 2/4: Crawling website content...", state="running") loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) result = loop.run_until_complete(crawler_service.crawl_website(url)) loop.close() if result.get('success', False): content = result.get('content', {}) # Step 3: Initialize style analyzer status.update(label="Step 3/4: Analyzing content style...", state="running") style_analyzer = StyleAnalyzer() # Step 4: Perform style analysis status.update(label="Step 4/4: Generating style recommendations...", state="running") style_analysis = style_analyzer.analyze_content_style(content) if style_analysis.get('error'): status.update(label="Analysis failed", state="error") st.error(f"Style analysis failed: {style_analysis['error']}") else: status.update(label="Analysis complete!", state="complete") # Display style analysis results display_style_analysis(style_analysis) # Display original content in tabs tab1, tab2, tab3 = st.tabs(["Content", "Metadata", "Links"]) with tab1: st.markdown("### Main Content") st.markdown(content.get('main_content', 'No content found')) with tab2: st.markdown("### Metadata") st.markdown(f""" **Title:** {content.get('title', 'No title found')} **Description:** {content.get('description', 'No description found')} **Meta Tags:** {content.get('meta_tags', {})} """) with tab3: st.markdown("### Links") for link in content.get('links', []): st.markdown(f"- [{link.get('text', '')}]({link.get('href', '')})") else: status.update(label="Crawling failed", state="error") st.error(f"Failed to analyze website: {result.get('error', 'Unknown error')}") except Exception as e: logger.error(f"Error during style analysis: {str(e)}") st.error(f"Analysis failed: {str(e)}") elif samples: with st.spinner("Analyzing content samples..."): try: # TODO: Implement sample text analysis st.info("Sample text analysis coming soon!") except Exception as e: logger.error(f"Error analyzing samples: {str(e)}") st.error(f"Analysis failed: {str(e)}") else: st.warning("Please provide either a website URL or content samples") with col2: st.markdown(""" ### How ALwrity Discovers Your Style **AI-Powered Style Analysis** ALwrity AI analyzes your existing content to understand your unique writing style and preferences. This helps us generate content that matches your voice perfectly. **Step 1: Content Analysis** We'll analyze your website content or written samples to understand: - Writing tone and voice - Vocabulary and language style - Content structure and formatting - Target audience and engagement style **Step 2: Style Recommendations** Based on the analysis, we'll provide: - Personalized writing guidelines - Content structure templates - Tone and voice recommendations - Audience engagement strategies **Step 3: Content Generation** Finally, we'll use these insights to: - Generate content that matches your style - Maintain consistency across all content - Optimize for your target audience - Ensure brand voice alignment """) except Exception as e: logger.error(f"Error in render_test_config_settings: {str(e)}") st.error(f"An error occurred: {str(e)}") if __name__ == "__main__": logger.info("Starting test config settings page") render_test_config_settings() logger.info("Test config settings page rendered successfully")