Spaces:
Sleeping
Sleeping
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)
|