Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from autogen import AssistantAgent, UserProxyAgent, GroupChatManager
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Initialize sentiment analysis pipeline
|
6 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
7 |
+
|
8 |
+
# Define specialized agents
|
9 |
+
class ThreatIntelAgent(AssistantAgent):
|
10 |
+
def __init__(self):
|
11 |
+
super().__init__(name="ThreatIntelAgent", system_message="You are a Threat Intelligence Agent. Analyze IoCs, malware, and threat feeds.")
|
12 |
+
|
13 |
+
def analyze_ioc(self, ioc):
|
14 |
+
# Placeholder for threat intelligence analysis
|
15 |
+
return f"Analyzed IoC: {ioc}. This matches known ransomware patterns."
|
16 |
+
|
17 |
+
class ComplianceAgent(AssistantAgent):
|
18 |
+
def __init__(self):
|
19 |
+
super().__init__(name="ComplianceAgent", system_message="You are a Compliance Agent. Handle regulatory queries and audit support.")
|
20 |
+
|
21 |
+
def check_compliance(self, query):
|
22 |
+
# Placeholder for compliance checks
|
23 |
+
return f"Compliance check for: {query}. This aligns with GDPR guidelines."
|
24 |
+
|
25 |
+
# Central AutoGen Manager
|
26 |
+
class AutoGenManager:
|
27 |
+
def __init__(self):
|
28 |
+
self.threat_intel_agent = ThreatIntelAgent()
|
29 |
+
self.compliance_agent = ComplianceAgent()
|
30 |
+
|
31 |
+
def route_request(self, user_input, user_role):
|
32 |
+
# Sentiment analysis
|
33 |
+
sentiment = sentiment_analyzer(user_input)[0]
|
34 |
+
print(f"Sentiment: {sentiment}")
|
35 |
+
|
36 |
+
# Route based on role and input
|
37 |
+
if user_role == "Threat Analyst":
|
38 |
+
return self.threat_intel_agent.analyze_ioc(user_input)
|
39 |
+
elif user_role == "Compliance Officer":
|
40 |
+
return self.compliance_agent.check_compliance(user_input)
|
41 |
+
else:
|
42 |
+
return "Request routed to general support."
|
43 |
+
|
44 |
+
# Gradio Interface
|
45 |
+
def chat_interface(user_input, user_role):
|
46 |
+
manager = AutoGenManager()
|
47 |
+
response = manager.route_request(user_input, user_role)
|
48 |
+
return response
|
49 |
+
|
50 |
+
# Create Gradio app
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
gr.Markdown("## AI-Powered Cybersecurity Assistant")
|
53 |
+
with gr.Row():
|
54 |
+
user_input = gr.Textbox(label="Your Request", placeholder="Enter your request here...")
|
55 |
+
user_role = gr.Dropdown(
|
56 |
+
label="Your Role",
|
57 |
+
choices=["Threat Analyst", "Compliance Officer", "Security Engineer", "General User"],
|
58 |
+
value="General User"
|
59 |
+
)
|
60 |
+
output = gr.Textbox(label="Response")
|
61 |
+
submit_btn = gr.Button("Submit")
|
62 |
+
submit_btn.click(fn=chat_interface, inputs=[user_input, user_role], outputs=output)
|
63 |
+
|
64 |
+
# Launch the app
|
65 |
+
if __name__ == "__main__":
|
66 |
+
demo.launch()
|