File size: 2,513 Bytes
0a2cf31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from autogen import AssistantAgent, UserProxyAgent, GroupChatManager
from transformers import pipeline

# Initialize sentiment analysis pipeline
sentiment_analyzer = pipeline("sentiment-analysis")

# Define specialized agents
class ThreatIntelAgent(AssistantAgent):
    def __init__(self):
        super().__init__(name="ThreatIntelAgent", system_message="You are a Threat Intelligence Agent. Analyze IoCs, malware, and threat feeds.")

    def analyze_ioc(self, ioc):
        # Placeholder for threat intelligence analysis
        return f"Analyzed IoC: {ioc}. This matches known ransomware patterns."

class ComplianceAgent(AssistantAgent):
    def __init__(self):
        super().__init__(name="ComplianceAgent", system_message="You are a Compliance Agent. Handle regulatory queries and audit support.")

    def check_compliance(self, query):
        # Placeholder for compliance checks
        return f"Compliance check for: {query}. This aligns with GDPR guidelines."

# Central AutoGen Manager
class AutoGenManager:
    def __init__(self):
        self.threat_intel_agent = ThreatIntelAgent()
        self.compliance_agent = ComplianceAgent()

    def route_request(self, user_input, user_role):
        # Sentiment analysis
        sentiment = sentiment_analyzer(user_input)[0]
        print(f"Sentiment: {sentiment}")

        # Route based on role and input
        if user_role == "Threat Analyst":
            return self.threat_intel_agent.analyze_ioc(user_input)
        elif user_role == "Compliance Officer":
            return self.compliance_agent.check_compliance(user_input)
        else:
            return "Request routed to general support."

# Gradio Interface
def chat_interface(user_input, user_role):
    manager = AutoGenManager()
    response = manager.route_request(user_input, user_role)
    return response

# Create Gradio app
with gr.Blocks() as demo:
    gr.Markdown("## AI-Powered Cybersecurity Assistant")
    with gr.Row():
        user_input = gr.Textbox(label="Your Request", placeholder="Enter your request here...")
        user_role = gr.Dropdown(
            label="Your Role",
            choices=["Threat Analyst", "Compliance Officer", "Security Engineer", "General User"],
            value="General User"
        )
    output = gr.Textbox(label="Response")
    submit_btn = gr.Button("Submit")
    submit_btn.click(fn=chat_interface, inputs=[user_input, user_role], outputs=output)

# Launch the app
if __name__ == "__main__":
    demo.launch()