File size: 2,164 Bytes
7fae465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
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)