Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,69 +2,84 @@ import os
|
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
4 |
from datetime import datetime
|
|
|
5 |
|
6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def analyze_data_for_gdpr(audit_data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
findings = {
|
9 |
-
"system_info":
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
"
|
15 |
-
"usage_percent": audit_data.get("disk_usage", {}).get("usage_percent", "Unknown"),
|
16 |
-
},
|
17 |
-
"network_info": {
|
18 |
-
"interfaces": audit_data.get("network_info", {}).get("interfaces", "Unknown"),
|
19 |
-
},
|
20 |
-
"security_measures": {
|
21 |
-
"encryption": audit_data.get("security_measures", {}).get("encryption", False),
|
22 |
-
"data_anonymization": audit_data.get("security_measures", {}).get("data_anonymization", False)
|
23 |
-
},
|
24 |
-
"running_processes": audit_data.get("running_processes", []),
|
25 |
-
"software_inventory": audit_data.get("software_inventory", [])
|
26 |
}
|
27 |
|
28 |
recommendations = []
|
29 |
-
if not
|
30 |
recommendations.append("Implement Encryption: Ensure that both stored and transmitted data are encrypted.")
|
31 |
-
if not
|
32 |
recommendations.append("Implement Data Anonymization: Ensure that sensitive data is anonymized during storage.")
|
33 |
|
34 |
return findings, recommendations
|
35 |
|
36 |
-
# Function to analyze audit data for PCI compliance
|
37 |
def analyze_data_for_pci(audit_data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
findings = {
|
39 |
-
"pci_security":
|
40 |
-
|
41 |
-
|
42 |
-
"intrusion_detection": audit_data.get("pci_security", {}).get("intrusion_detection", False),
|
43 |
-
},
|
44 |
-
"card_data_security": {
|
45 |
-
"encryption": audit_data.get("card_data_security", {}).get("encryption", False),
|
46 |
-
"storage_protection": audit_data.get("card_data_security", {}).get("storage_protection", False)
|
47 |
-
},
|
48 |
-
"network_configurations": audit_data.get("network_configurations", [])
|
49 |
}
|
50 |
|
51 |
recommendations = []
|
52 |
-
if not
|
53 |
recommendations.append("Implement Firewall: Ensure that a firewall is in place to protect the network.")
|
54 |
-
if not
|
55 |
recommendations.append("Encrypt Card Data: Ensure all cardholder data is encrypted during storage and transmission.")
|
56 |
|
57 |
return findings, recommendations
|
58 |
|
59 |
-
# Generate GDPR Compliance Report
|
60 |
def generate_gdpr_report(audit_data, company_name="Company Name", system_name="System Name"):
|
61 |
findings, recommendations = analyze_data_for_gdpr(audit_data)
|
62 |
|
63 |
-
report_content =
|
64 |
GDPR Compliance Evaluation Report
|
65 |
|
66 |
Title: GDPR Compliance Evaluation Report
|
67 |
-
Date: {
|
68 |
Prepared by: [Your Name]
|
69 |
For: {company_name}
|
70 |
|
@@ -74,42 +89,49 @@ def generate_gdpr_report(audit_data, company_name="Company Name", system_name="S
|
|
74 |
and suggests recommendations to enhance GDPR adherence.
|
75 |
|
76 |
Findings:
|
77 |
-
System Information:
|
78 |
-
|
79 |
-
- Architecture: {findings['system_info']['architecture']}
|
80 |
-
- Memory: {findings['system_info']['memory']}
|
81 |
|
82 |
-
Disk Usage:
|
83 |
-
|
84 |
|
85 |
-
Network Info:
|
86 |
-
|
87 |
|
88 |
-
Security Measures:
|
89 |
-
|
90 |
-
- Data Anonymization: {"Yes" if findings['security_measures']['data_anonymization'] else "No"}
|
91 |
|
92 |
-
Running Processes:
|
93 |
-
|
94 |
|
95 |
-
Software Inventory:
|
96 |
-
|
97 |
|
98 |
Recommendations:
|
99 |
-
{
|
100 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
return report_content
|
103 |
|
104 |
-
# Generate PCI Compliance Report
|
105 |
def generate_pci_report(audit_data, company_name="Company Name", system_name="System Name"):
|
106 |
findings, recommendations = analyze_data_for_pci(audit_data)
|
107 |
|
108 |
-
report_content =
|
109 |
PCI Compliance Evaluation Report
|
110 |
|
111 |
Title: PCI Compliance Evaluation Report
|
112 |
-
Date: {
|
113 |
Prepared by: [Your Name]
|
114 |
For: {company_name}
|
115 |
|
@@ -119,21 +141,25 @@ def generate_pci_report(audit_data, company_name="Company Name", system_name="Sy
|
|
119 |
and suggests recommendations to enhance PCI DSS adherence.
|
120 |
|
121 |
Findings:
|
122 |
-
PCI Security Measures:
|
123 |
-
|
124 |
-
- Antivirus: {"Yes" if findings['pci_security']['antivirus'] else "No"}
|
125 |
-
- Intrusion Detection: {"Yes" if findings['pci_security']['intrusion_detection'] else "No"}
|
126 |
|
127 |
-
Card Data Security:
|
128 |
-
|
129 |
-
- Storage Protection: {"Yes" if findings['card_data_security']['storage_protection'] else "No"}
|
130 |
|
131 |
-
Network Configurations:
|
132 |
-
|
133 |
|
134 |
Recommendations:
|
135 |
-
{
|
136 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
return report_content
|
139 |
|
|
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
4 |
from datetime import datetime
|
5 |
+
from transformers import pipeline
|
6 |
|
7 |
+
# Initialize a question-answering pipeline (You can replace the model with any capable one)
|
8 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
9 |
+
|
10 |
+
# Function to analyze each section with prompts
|
11 |
+
def prompt_based_analysis(question, context):
|
12 |
+
response = qa_pipeline(question=question, context=context)
|
13 |
+
return response['answer']
|
14 |
+
|
15 |
+
# Function to analyze audit data for GDPR compliance using prompts
|
16 |
def analyze_data_for_gdpr(audit_data):
|
17 |
+
system_info_context = f"OS Version: {audit_data.get('os_version', 'Unknown')}, Architecture: {audit_data.get('architecture', 'Unknown')}, Memory: {audit_data.get('memory', 'Unknown')}"
|
18 |
+
disk_usage_context = f"Disk Usage: {audit_data.get('disk_usage', {}).get('usage_percent', 'Unknown')}%"
|
19 |
+
network_info_context = f"Interfaces: {', '.join(audit_data.get('network_info', {}).get('interfaces', []))}"
|
20 |
+
security_measures_context = f"Encryption: {audit_data.get('security_measures', {}).get('encryption', False)}, Data Anonymization: {audit_data.get('security_measures', {}).get('data_anonymization', False)}"
|
21 |
+
processes_context = f"Running Processes: {', '.join(audit_data.get('running_processes', []))}"
|
22 |
+
software_inventory_context = f"Software Installed: {', '.join(audit_data.get('software_inventory', []))}"
|
23 |
+
|
24 |
+
# Prompts for each section
|
25 |
+
system_info_analysis = prompt_based_analysis("Evaluate the system information in terms of GDPR compliance.", system_info_context)
|
26 |
+
disk_usage_analysis = prompt_based_analysis("Evaluate the disk usage with respect to GDPR regulations.", disk_usage_context)
|
27 |
+
network_info_analysis = prompt_based_analysis("Evaluate the network information in terms of GDPR compliance.", network_info_context)
|
28 |
+
security_measures_analysis = prompt_based_analysis("Evaluate the current security measures for compliance with GDPR.", security_measures_context)
|
29 |
+
processes_analysis = prompt_based_analysis("Evaluate the running processes for GDPR compliance.", processes_context)
|
30 |
+
software_inventory_analysis = prompt_based_analysis("Evaluate the installed software for GDPR compliance.", software_inventory_context)
|
31 |
+
|
32 |
findings = {
|
33 |
+
"system_info": system_info_analysis,
|
34 |
+
"disk_usage": disk_usage_analysis,
|
35 |
+
"network_info": network_info_analysis,
|
36 |
+
"security_measures": security_measures_analysis,
|
37 |
+
"running_processes": processes_analysis,
|
38 |
+
"software_inventory": software_inventory_analysis,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
|
41 |
recommendations = []
|
42 |
+
if 'encryption' not in security_measures_context.lower():
|
43 |
recommendations.append("Implement Encryption: Ensure that both stored and transmitted data are encrypted.")
|
44 |
+
if 'anonymization' not in security_measures_context.lower():
|
45 |
recommendations.append("Implement Data Anonymization: Ensure that sensitive data is anonymized during storage.")
|
46 |
|
47 |
return findings, recommendations
|
48 |
|
49 |
+
# Function to analyze audit data for PCI compliance using prompts
|
50 |
def analyze_data_for_pci(audit_data):
|
51 |
+
pci_security_context = f"Firewall: {audit_data.get('pci_security', {}).get('firewall', False)}, Antivirus: {audit_data.get('pci_security', {}).get('antivirus', False)}, Intrusion Detection: {audit_data.get('pci_security', {}).get('intrusion_detection', False)}"
|
52 |
+
card_data_security_context = f"Card Data Encryption: {audit_data.get('card_data_security', {}).get('encryption', False)}, Storage Protection: {audit_data.get('card_data_security', {}).get('storage_protection', False)}"
|
53 |
+
network_config_context = f"Network Configurations: {', '.join(audit_data.get('network_configurations', []))}"
|
54 |
+
|
55 |
+
# Prompts for each section
|
56 |
+
pci_security_analysis = prompt_based_analysis("Evaluate the PCI security measures for compliance with PCI DSS.", pci_security_context)
|
57 |
+
card_data_security_analysis = prompt_based_analysis("Evaluate the card data security measures for PCI DSS compliance.", card_data_security_context)
|
58 |
+
network_config_analysis = prompt_based_analysis("Evaluate the network configurations for PCI DSS compliance.", network_config_context)
|
59 |
+
|
60 |
findings = {
|
61 |
+
"pci_security": pci_security_analysis,
|
62 |
+
"card_data_security": card_data_security_analysis,
|
63 |
+
"network_configurations": network_config_analysis,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
|
66 |
recommendations = []
|
67 |
+
if 'firewall' not in pci_security_context.lower():
|
68 |
recommendations.append("Implement Firewall: Ensure that a firewall is in place to protect the network.")
|
69 |
+
if 'encryption' not in card_data_security_context.lower():
|
70 |
recommendations.append("Encrypt Card Data: Ensure all cardholder data is encrypted during storage and transmission.")
|
71 |
|
72 |
return findings, recommendations
|
73 |
|
74 |
+
# Generate GDPR Compliance Report with advanced prompts for each section
|
75 |
def generate_gdpr_report(audit_data, company_name="Company Name", system_name="System Name"):
|
76 |
findings, recommendations = analyze_data_for_gdpr(audit_data)
|
77 |
|
78 |
+
report_content = """
|
79 |
GDPR Compliance Evaluation Report
|
80 |
|
81 |
Title: GDPR Compliance Evaluation Report
|
82 |
+
Date: {date}
|
83 |
Prepared by: [Your Name]
|
84 |
For: {company_name}
|
85 |
|
|
|
89 |
and suggests recommendations to enhance GDPR adherence.
|
90 |
|
91 |
Findings:
|
92 |
+
System Information Analysis:
|
93 |
+
{system_info}
|
|
|
|
|
94 |
|
95 |
+
Disk Usage Analysis:
|
96 |
+
{disk_usage}
|
97 |
|
98 |
+
Network Info Analysis:
|
99 |
+
{network_info}
|
100 |
|
101 |
+
Security Measures Analysis:
|
102 |
+
{security_measures}
|
|
|
103 |
|
104 |
+
Running Processes Analysis:
|
105 |
+
{running_processes}
|
106 |
|
107 |
+
Software Inventory Analysis:
|
108 |
+
{software_inventory}
|
109 |
|
110 |
Recommendations:
|
111 |
+
{recommendations}
|
112 |
+
""".format(
|
113 |
+
date=datetime.now().strftime('%Y-%m-%d'),
|
114 |
+
company_name=company_name,
|
115 |
+
system_info=findings['system_info'],
|
116 |
+
disk_usage=findings['disk_usage'],
|
117 |
+
network_info=findings['network_info'],
|
118 |
+
security_measures=findings['security_measures'],
|
119 |
+
running_processes=findings['running_processes'],
|
120 |
+
software_inventory=findings['software_inventory'],
|
121 |
+
recommendations=''.join(f'- {rec}\n' for rec in recommendations)
|
122 |
+
)
|
123 |
|
124 |
return report_content
|
125 |
|
126 |
+
# Generate PCI Compliance Report with advanced prompts for each section
|
127 |
def generate_pci_report(audit_data, company_name="Company Name", system_name="System Name"):
|
128 |
findings, recommendations = analyze_data_for_pci(audit_data)
|
129 |
|
130 |
+
report_content = """
|
131 |
PCI Compliance Evaluation Report
|
132 |
|
133 |
Title: PCI Compliance Evaluation Report
|
134 |
+
Date: {date}
|
135 |
Prepared by: [Your Name]
|
136 |
For: {company_name}
|
137 |
|
|
|
141 |
and suggests recommendations to enhance PCI DSS adherence.
|
142 |
|
143 |
Findings:
|
144 |
+
PCI Security Measures Analysis:
|
145 |
+
{pci_security}
|
|
|
|
|
146 |
|
147 |
+
Card Data Security Analysis:
|
148 |
+
{card_data_security}
|
|
|
149 |
|
150 |
+
Network Configurations Analysis:
|
151 |
+
{network_configurations}
|
152 |
|
153 |
Recommendations:
|
154 |
+
{recommendations}
|
155 |
+
""".format(
|
156 |
+
date=datetime.now().strftime('%Y-%m-%d'),
|
157 |
+
company_name=company_name,
|
158 |
+
pci_security=findings['pci_security'],
|
159 |
+
card_data_security=findings['card_data_security'],
|
160 |
+
network_configurations=findings['network_configurations'],
|
161 |
+
recommendations=''.join(f'- {rec}\n' for rec in recommendations)
|
162 |
+
)
|
163 |
|
164 |
return report_content
|
165 |
|