Spaces:
Paused
Paused
File size: 7,958 Bytes
4290ae1 cbe8e15 4290ae1 cbe8e15 4290ae1 cbe8e15 583e302 4290ae1 cbe8e15 4290ae1 cbe8e15 4290ae1 cbe8e15 0e15dd4 583e302 cbe8e15 4290ae1 bafd45f 583e302 cbe8e15 bafd45f 583e302 cbe8e15 bafd45f cbe8e15 bafd45f cbe8e15 bafd45f cbe8e15 583e302 cbe8e15 4290ae1 cbe8e15 4290ae1 cbe8e15 4290ae1 0e15dd4 4290ae1 0e15dd4 4290ae1 cbe8e15 4290ae1 | 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | import gradio as gr
import os
import time
from crewai import Agent, Task, Crew
from langchain_openai import ChatOpenAI
# Secure API key entry
os.getenv("OPENAI_API_KEY") # Enter your OpenAI API key
def analyze_scam(message_content):
if not message_content.strip():
return "β Please enter a message or URL to analyze."
loading_messages = [
"π‘οΈ Initializing AI security team...",
"π Claim Extractor analyzing suspicious content...",
"βοΈ Fact Checker verifying claims and patterns...",
"π Safety Advisor preparing guidance report...",
"π¨ Generating comprehensive scam analysis..."
]
yield loading_messages[0]
try:
llm = ChatOpenAI(model_name="gpt-4o-mini", temperature=0.1)
for i, message in enumerate(loading_messages[1:], 1):
time.sleep(2)
yield message
extractor_agent = Agent(
role="Claim Extractor",
goal="Extract key claims, offers, and suspicious elements from messages or URLs",
backstory="Expert at parsing and identifying key claims in potentially fraudulent messages.",
llm=llm,
verbose=False
)
verifier_agent = Agent(
role="Fact Checker",
goal="Verify claims and assess scam probability using heuristic rules and pattern matching",
backstory="Cybersecurity expert who specializes in identifying scam patterns.",
llm=llm,
verbose=False
)
explainer_agent = Agent(
role="Safety Advisor",
goal="Provide clear, actionable guidance to users about potential scams",
backstory="Digital safety educator who explains complex security issues simply.",
llm=llm,
verbose=False
)
extract_task = Task(
description=f"Analyze and extract suspicious elements from: {message_content}",
expected_output="Structured summary of extracted claims, suspicious elements, and language patterns",
agent=extractor_agent
)
verify_task = Task(
description="Risk assessment with scam probability score, red flags, and evidence",
expected_output="Risk assessment with scam probability score, red flags, and evidence",
agent=verifier_agent,
context=[extract_task]
)
explain_task = Task(
description="User-friendly safety report with clear recommendations and next steps",
expected_output="User-friendly safety report with clear recommendations and next steps",
agent=explainer_agent,
context=[extract_task, verify_task]
)
crew = Crew(
agents=[extractor_agent, verifier_agent, explainer_agent],
tasks=[extract_task, verify_task, explain_task],
verbose=False,
process="sequential"
)
yield "π― AI agents collaborating on final analysis..."
result = crew.kickoff()
yield str(result)
except Exception as e:
yield f"β Scam analysis failed: {str(e)}"
def create_gradio_interface():
with gr.Blocks(title="Scam-Signal Verifier | AI Security Analysis", theme=gr.themes.Default()) as interface:
# Custom CSS for better contrast
gr.HTML("""
<style>
.team-section { background: #f8f9fa; padding: 2rem; border-radius: 15px; margin-bottom: 2rem; }
.team-title { text-align: center; margin-bottom: 1.5rem; font-size: 1.4rem; font-weight: bold; color: #1f2937; }
.team-role { font-weight: bold; color: #111827; }
.team-desc { font-size: 0.9rem; color: #374151; margin-top: 0.5rem; }
</style>
""")
# Header
gr.HTML("""
<div style="text-align: center; padding: 2rem 0;">
<h1 style="font-size: 3rem; margin-bottom: 1rem; color: #111827;">π‘οΈ Scam-Signal Verifier</h1>
<p style="font-size: 1.2rem; color: #4b5563;">
AI-powered protection against phishing and fraudulent messages
</p>
</div>
""")
# AI Security Team
gr.HTML("""
<div class="team-section">
<div class="team-title">π€ Your AI Security Team</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem;">
<div style="text-align: center; padding: 1rem;">
<div style="font-size: 2rem;">π</div>
<div class="team-role">Claim Extractor</div>
<div class="team-desc">Identifies suspicious content and claims</div>
</div>
<div style="text-align: center; padding: 1rem;">
<div style="font-size: 2rem;">βοΈ</div>
<div class="team-role">Fact Checker</div>
<div class="team-desc">Verifies claims and calculates risk</div>
</div>
<div style="text-align: center; padding: 1rem;">
<div style="font-size: 2rem;">π</div>
<div class="team-role">Safety Advisor</div>
<div class="team-desc">Provides clear guidance and next steps</div>
</div>
</div>
</div>
""")
# Input Section
gr.HTML("<h3 style='text-align: center; margin-bottom: 1rem;'>π± Analyze Suspicious Message or URL</h3>")
message_input = gr.Textbox(
label="π¨ Suspicious Message or URL",
placeholder="Paste the suspicious message, email content, or URL you want to verify...",
lines=5
)
analyze_btn = gr.Button("π Analyze for Scams", variant="primary", size="lg")
# Output Section β restored to original
output = gr.Textbox(
label="π Scam Analysis Report",
lines=25,
show_copy_button=True,
placeholder="Your detailed scam analysis will appear here..."
)
# Examples
gr.Examples(
examples=[
["URGENT: Your account will be suspended! Click here immediately to verify: http://suspicious-bank-verify.tk/login"],
["Congratulations! You've won $10,000! Claim your prize now by clicking this link and entering your bank details."],
["Your package is held at customs. Pay $50 shipping fee to release: https://bit.ly/customs-fee-pay"],
["FINAL NOTICE: IRS requires immediate payment of $2,500 or face legal action. Call now: 555-SCAM"],
["Hello dear, I am Prince Williams from Nigeria with $10 million to share with you..."],
],
inputs=message_input,
label="π§ͺ Try These Example Scams"
)
# Footer
gr.HTML("""
<div style="text-align: center; padding: 2rem; margin-top: 2rem; border-top: 1px solid #eee;">
<p><strong>Scam-Signal Verifier</strong> β’ AI-Powered Fraud Detection</p>
<p style="font-size: 0.9rem; color: #666;">
β οΈ This tool helps identify potential scams but is not 100% accurate. Always verify independently.
</p>
</div>
""")
# Event Handlers
analyze_btn.click(fn=analyze_scam, inputs=[message_input], outputs=output, show_progress=True)
message_input.submit(fn=analyze_scam, inputs=[message_input], outputs=output, show_progress=True)
return interface
if __name__ == "__main__":
app = create_gradio_interface()
app.launch(share=False, server_name="0.0.0.0", server_port=7860, show_api=False, inbrowser=False) |