""" Policy Summarizer - Gradio App """ import gradio as gr from dotenv import load_dotenv from crew import run_policy_analysis from utils.validators import validate_url, is_likely_policy_url from utils.logger import format_logs_for_display, clear_logs load_dotenv() def process_policy(url: str): """Process a policy URL and return summary + logs""" clear_logs() # Validate URL is_valid, error_msg = validate_url(url) if not is_valid: return f"❌ **Invalid URL:** {error_msg}", "Validation failed" # Warning for non-policy URLs warning = "" if not is_likely_policy_url(url): warning = "⚠️ This URL may not be a policy page.\n\n" try: result = run_policy_analysis(url) logs = format_logs_for_display() return warning + result, logs except Exception as e: return f"❌ **Error:** {str(e)}", format_logs_for_display() # Create Gradio interface with gr.Blocks(title="Policy Summarizer") as app: gr.Markdown("# 🔍 Policy Summarizer") gr.Markdown(""" Paste a link to any Privacy Policy or Terms of Service, and AI agents will: - 📄 **Summarize** the key points - ✅ **Highlight** your rights - ⚠️ **Warn** about concerns """) with gr.Row(): url_input = gr.Textbox( label="Policy URL", placeholder="https://example.com/privacy-policy", scale=4 ) analyze_btn = gr.Button("🔍 Analyze", variant="primary", scale=1) gr.Markdown("### Examples:") gr.Markdown("- https://discord.com/privacy") gr.Markdown("- https://www.spotify.com/legal/privacy-policy/") with gr.Tabs(): with gr.TabItem("📋 Summary"): output_summary = gr.Markdown(value="*Enter a URL and click Analyze*") with gr.TabItem("📊 Logs"): output_logs = gr.Markdown(value="*Logs appear here*") analyze_btn.click( fn=process_policy, inputs=[url_input], outputs=[output_summary, output_logs] ) if __name__ == "__main__": app.launch(server_name="0.0.0.0", server_port=7860)