AayanSuleri commited on
Commit
4290ae1
Β·
verified Β·
1 Parent(s): 348f0ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -21
app.py CHANGED
@@ -1,18 +1,16 @@
1
- from flask import Flask, render_template, request, jsonify
2
  import os
3
  import time
4
  from crewai import Agent, Task, Crew
5
  from langchain_openai import ChatOpenAI
6
 
7
- app = Flask(__name__)
 
8
 
9
- # Ensure API key is set in environment
10
- os.getenv("OPENAI_API_KEY") # Enter your OpenAI API key or set it via env var
11
-
12
- def run_scam_analysis(message_content):
13
  if not message_content.strip():
14
  return "❗ Please enter a message or URL to analyze."
15
-
16
  loading_messages = [
17
  "πŸ›‘οΈ Initializing AI security team...",
18
  "πŸ” Claim Extractor analyzing suspicious content...",
@@ -20,10 +18,16 @@ def run_scam_analysis(message_content):
20
  "πŸ“‹ Safety Advisor preparing guidance report...",
21
  "🚨 Generating comprehensive scam analysis..."
22
  ]
23
-
 
 
24
  try:
25
  llm = ChatOpenAI(model_name="gpt-4o-mini", temperature=0.1)
26
 
 
 
 
 
27
  extractor_agent = Agent(
28
  role="Claim Extractor",
29
  goal="Extract key claims, offers, and suspicious elements from messages or URLs",
@@ -33,7 +37,7 @@ def run_scam_analysis(message_content):
33
  )
34
 
35
  verifier_agent = Agent(
36
- role="Fact Checker",
37
  goal="Verify claims and assess scam probability using heuristic rules and pattern matching",
38
  backstory="Cybersecurity expert who specializes in identifying scam patterns.",
39
  llm=llm,
@@ -75,22 +79,109 @@ def run_scam_analysis(message_content):
75
  process="sequential"
76
  )
77
 
 
 
78
  result = crew.kickoff()
79
- return str(result)
80
 
81
  except Exception as e:
82
- return f"❌ Scam analysis failed: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
- @app.route("/")
85
- def index():
86
- return render_template("index.html")
 
 
 
 
 
 
 
 
 
87
 
88
- @app.route("/analyze", methods=["POST"])
89
- def analyze():
90
- data = request.get_json()
91
- message = data.get("message", "")
92
- result = run_scam_analysis(message)
93
- return jsonify({"result": result})
 
 
 
 
 
 
 
 
 
94
 
95
  if __name__ == "__main__":
96
- app.run(host="0.0.0.0", port=7860)
 
 
1
+ import gradio as gr
2
  import os
3
  import time
4
  from crewai import Agent, Task, Crew
5
  from langchain_openai import ChatOpenAI
6
 
7
+ # Secure API key entry
8
+ os.getenv("OPENAI_API_KEY") # Enter your OpenAI API key
9
 
10
+ def analyze_scam(message_content):
 
 
 
11
  if not message_content.strip():
12
  return "❗ Please enter a message or URL to analyze."
13
+
14
  loading_messages = [
15
  "πŸ›‘οΈ Initializing AI security team...",
16
  "πŸ” Claim Extractor analyzing suspicious content...",
 
18
  "πŸ“‹ Safety Advisor preparing guidance report...",
19
  "🚨 Generating comprehensive scam analysis..."
20
  ]
21
+
22
+ yield loading_messages[0]
23
+
24
  try:
25
  llm = ChatOpenAI(model_name="gpt-4o-mini", temperature=0.1)
26
 
27
+ for i, message in enumerate(loading_messages[1:], 1):
28
+ time.sleep(2)
29
+ yield message
30
+
31
  extractor_agent = Agent(
32
  role="Claim Extractor",
33
  goal="Extract key claims, offers, and suspicious elements from messages or URLs",
 
37
  )
38
 
39
  verifier_agent = Agent(
40
+ role="Fact Checker",
41
  goal="Verify claims and assess scam probability using heuristic rules and pattern matching",
42
  backstory="Cybersecurity expert who specializes in identifying scam patterns.",
43
  llm=llm,
 
79
  process="sequential"
80
  )
81
 
82
+ yield "🎯 AI agents collaborating on final analysis..."
83
+
84
  result = crew.kickoff()
85
+ yield str(result)
86
 
87
  except Exception as e:
88
+ yield f"❌ Scam analysis failed: {str(e)}"
89
+
90
+ def create_gradio_interface():
91
+ with gr.Blocks(title="Scam-Signal Verifier | AI Security Analysis", theme=gr.themes.Default()) as interface:
92
+
93
+ # Custom CSS for better contrast
94
+ gr.HTML("""
95
+ <style>
96
+ .team-section { background: #f8f9fa; padding: 2rem; border-radius: 15px; margin-bottom: 2rem; }
97
+ .team-title { text-align: center; margin-bottom: 1.5rem; font-size: 1.4rem; font-weight: bold; color: #1f2937; }
98
+ .team-role { font-weight: bold; color: #111827; }
99
+ .team-desc { font-size: 0.9rem; color: #374151; margin-top: 0.5rem; }
100
+ </style>
101
+ """)
102
+
103
+ # Header
104
+ gr.HTML("""
105
+ <div style="text-align: center; padding: 2rem 0;">
106
+ <h1 style="font-size: 3rem; margin-bottom: 1rem; color: #111827;">πŸ›‘οΈ Scam-Signal Verifier</h1>
107
+ <p style="font-size: 1.2rem; color: #4b5563;">
108
+ AI-powered protection against phishing and fraudulent messages
109
+ </p>
110
+ </div>
111
+ """)
112
+
113
+ # AI Security Team
114
+ gr.HTML("""
115
+ <div class="team-section">
116
+ <div class="team-title">πŸ€– Your AI Security Team</div>
117
+ <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem;">
118
+ <div style="text-align: center; padding: 1rem;">
119
+ <div style="font-size: 2rem;">πŸ”</div>
120
+ <div class="team-role">Claim Extractor</div>
121
+ <div class="team-desc">Identifies suspicious content and claims</div>
122
+ </div>
123
+ <div style="text-align: center; padding: 1rem;">
124
+ <div style="font-size: 2rem;">βš–οΈ</div>
125
+ <div class="team-role">Fact Checker</div>
126
+ <div class="team-desc">Verifies claims and calculates risk</div>
127
+ </div>
128
+ <div style="text-align: center; padding: 1rem;">
129
+ <div style="font-size: 2rem;">πŸ“‹</div>
130
+ <div class="team-role">Safety Advisor</div>
131
+ <div class="team-desc">Provides clear guidance and next steps</div>
132
+ </div>
133
+ </div>
134
+ </div>
135
+ """)
136
+
137
+ # Input Section
138
+ gr.HTML("<h3 style='text-align: center; margin-bottom: 1rem;'>πŸ“± Analyze Suspicious Message or URL</h3>")
139
+
140
+ message_input = gr.Textbox(
141
+ label="🚨 Suspicious Message or URL",
142
+ placeholder="Paste the suspicious message, email content, or URL you want to verify...",
143
+ lines=5
144
+ )
145
+
146
+ analyze_btn = gr.Button("πŸ” Analyze for Scams", variant="primary", size="lg")
147
+
148
+ # Output Section β€” restored to original
149
+ output = gr.Textbox(
150
+ label="πŸ“Š Scam Analysis Report",
151
+ lines=25,
152
+ show_copy_button=True,
153
+ placeholder="Your detailed scam analysis will appear here..."
154
+ )
155
 
156
+ # Examples
157
+ gr.Examples(
158
+ examples=[
159
+ ["URGENT: Your account will be suspended! Click here immediately to verify: http://suspicious-bank-verify.tk/login"],
160
+ ["Congratulations! You've won $10,000! Claim your prize now by clicking this link and entering your bank details."],
161
+ ["Your package is held at customs. Pay $50 shipping fee to release: https://bit.ly/customs-fee-pay"],
162
+ ["FINAL NOTICE: IRS requires immediate payment of $2,500 or face legal action. Call now: 555-SCAM"],
163
+ ["Hello dear, I am Prince Williams from Nigeria with $10 million to share with you..."],
164
+ ],
165
+ inputs=message_input,
166
+ label="πŸ§ͺ Try These Example Scams"
167
+ )
168
 
169
+ # Footer
170
+ gr.HTML("""
171
+ <div style="text-align: center; padding: 2rem; margin-top: 2rem; border-top: 1px solid #eee;">
172
+ <p><strong>Scam-Signal Verifier</strong> β€’ AI-Powered Fraud Detection</p>
173
+ <p style="font-size: 0.9rem; color: #666;">
174
+ ⚠️ This tool helps identify potential scams but is not 100% accurate. Always verify independently.
175
+ </p>
176
+ </div>
177
+ """)
178
+
179
+ # Event Handlers
180
+ analyze_btn.click(fn=analyze_scam, inputs=[message_input], outputs=output, show_progress=True)
181
+ message_input.submit(fn=analyze_scam, inputs=[message_input], outputs=output, show_progress=True)
182
+
183
+ return interface
184
 
185
  if __name__ == "__main__":
186
+ app = create_gradio_interface()
187
+ app.launch(share=False, server_name="0.0.0.0", server_port=7860, show_api=False, inbrowser=False)