Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,16 +4,19 @@ import gradio as gr
|
|
4 |
from datetime import datetime
|
5 |
from transformers import pipeline
|
6 |
|
7 |
-
# Initialize a question-answering pipeline
|
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 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
# Function to analyze audit data for GDPR compliance using prompts
|
16 |
-
def
|
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', []))}"
|
@@ -22,13 +25,14 @@ def analyze_data_for_gdpr(audit_data):
|
|
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
|
26 |
-
disk_usage_analysis = prompt_based_analysis("Evaluate the disk usage
|
27 |
-
network_info_analysis = prompt_based_analysis("Evaluate the network
|
28 |
-
security_measures_analysis = prompt_based_analysis("
|
29 |
-
processes_analysis = prompt_based_analysis("
|
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,
|
@@ -38,48 +42,34 @@ def analyze_data_for_gdpr(audit_data):
|
|
38 |
"software_inventory": software_inventory_analysis,
|
39 |
}
|
40 |
|
|
|
41 |
recommendations = []
|
42 |
-
if
|
43 |
-
recommendations.append("
|
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 |
-
|
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 |
-
|
56 |
-
|
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 |
-
|
61 |
-
"
|
62 |
-
"card_data_security": card_data_security_analysis,
|
63 |
-
"network_configurations": network_config_analysis,
|
64 |
-
}
|
65 |
|
66 |
-
|
67 |
-
|
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 =
|
77 |
|
78 |
-
report_content = """
|
79 |
GDPR Compliance Evaluation Report
|
80 |
|
81 |
Title: GDPR Compliance Evaluation Report
|
82 |
-
Date: {
|
83 |
Prepared by: [Your Name]
|
84 |
For: {company_name}
|
85 |
|
@@ -88,78 +78,36 @@ def generate_gdpr_report(audit_data, company_name="Company Name", system_name="S
|
|
88 |
Based on the system audit and analysis of data handling processes, this report provides findings, identifies compliance gaps,
|
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 |
-
|
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 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
Date: {date}
|
135 |
-
Prepared by: [Your Name]
|
136 |
-
For: {company_name}
|
137 |
-
|
138 |
-
Executive Summary:
|
139 |
-
This report evaluates the compliance of {company_name} with the Payment Card Industry Data Security Standard (PCI DSS).
|
140 |
-
Based on the system audit and analysis of data handling processes, this report provides findings, identifies compliance gaps,
|
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 |
|
@@ -188,20 +136,18 @@ with gr.Blocks() as demo:
|
|
188 |
csv_file = gr.File(label="Upload CSV file")
|
189 |
|
190 |
gdpr_compliance = gr.Textbox(lines=10, placeholder="GDPR Compliance Analysis...", label="GDPR Compliance Analysis")
|
191 |
-
pci_compliance = gr.Textbox(lines=10, placeholder="PCI Compliance Analysis...", label="PCI Compliance Analysis")
|
192 |
|
193 |
def run_compliance_checks(csv_file):
|
194 |
if csv_file is None:
|
195 |
-
return "No file uploaded"
|
196 |
audit_data = analyze_csv_file(csv_file)
|
197 |
gdpr_report = generate_gdpr_report(audit_data)
|
198 |
-
|
199 |
-
return gdpr_report, pci_report
|
200 |
|
201 |
check_compliance_btn = gr.Button("Run Compliance Checks")
|
202 |
-
check_compliance_btn.click(run_compliance_checks, inputs=[csv_file], outputs=[gdpr_compliance
|
203 |
|
204 |
clear_btn = gr.Button("Clear")
|
205 |
-
clear_btn.click(lambda:
|
206 |
|
207 |
demo.launch(share=True)
|
|
|
4 |
from datetime import datetime
|
5 |
from transformers import pipeline
|
6 |
|
7 |
+
# Initialize a question-answering pipeline
|
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 |
+
try:
|
13 |
+
response = qa_pipeline(question=question, context=context)
|
14 |
+
return response['answer']
|
15 |
+
except Exception as e:
|
16 |
+
return f"Error analyzing data: {str(e)}"
|
17 |
|
18 |
# Function to analyze audit data for GDPR compliance using prompts
|
19 |
+
def analyze_gdpr_compliance(audit_data):
|
20 |
system_info_context = f"OS Version: {audit_data.get('os_version', 'Unknown')}, Architecture: {audit_data.get('architecture', 'Unknown')}, Memory: {audit_data.get('memory', 'Unknown')}"
|
21 |
disk_usage_context = f"Disk Usage: {audit_data.get('disk_usage', {}).get('usage_percent', 'Unknown')}%"
|
22 |
network_info_context = f"Interfaces: {', '.join(audit_data.get('network_info', {}).get('interfaces', []))}"
|
|
|
25 |
software_inventory_context = f"Software Installed: {', '.join(audit_data.get('software_inventory', []))}"
|
26 |
|
27 |
# Prompts for each section
|
28 |
+
system_info_analysis = prompt_based_analysis("Evaluate the system information for GDPR compliance. Highlight any potential risks related to OS version, architecture, and memory.", system_info_context)
|
29 |
+
disk_usage_analysis = prompt_based_analysis("Evaluate the disk usage in terms of GDPR compliance. Discuss data storage practices, retention policies, and any storage-related risks.", disk_usage_context)
|
30 |
+
network_info_analysis = prompt_based_analysis("Evaluate the network interfaces in terms of GDPR compliance. Focus on potential risks related to network security and data transmission.", network_info_context)
|
31 |
+
security_measures_analysis = prompt_based_analysis("Assess the security measures for GDPR compliance, particularly encryption and data anonymization. Identify any weaknesses or gaps in data protection.", security_measures_context)
|
32 |
+
processes_analysis = prompt_based_analysis("Analyze the running processes for GDPR compliance. Identify potential vulnerabilities and risks related to the execution of unauthorized processes.", processes_context)
|
33 |
+
software_inventory_analysis = prompt_based_analysis("Evaluate the installed software for GDPR compliance. Highlight any outdated or vulnerable software that could pose risks.", software_inventory_context)
|
34 |
+
|
35 |
+
# Findings organized by section
|
36 |
findings = {
|
37 |
"system_info": system_info_analysis,
|
38 |
"disk_usage": disk_usage_analysis,
|
|
|
42 |
"software_inventory": software_inventory_analysis,
|
43 |
}
|
44 |
|
45 |
+
# Recommendations based on the findings
|
46 |
recommendations = []
|
47 |
+
if "Unknown" in system_info_context:
|
48 |
+
recommendations.append("Review System Information: Ensure that the OS, architecture, and memory configurations are well documented and up to date.")
|
|
|
|
|
49 |
|
50 |
+
if 'not encrypted' in security_measures_analysis.lower() or 'no encryption' in security_measures_analysis.lower():
|
51 |
+
recommendations.append("Implement Encryption: Ensure that both stored and transmitted data are encrypted.")
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
if 'not anonymized' in security_measures_analysis.lower():
|
54 |
+
recommendations.append("Implement Data Anonymization: Ensure that sensitive data is anonymized during storage.")
|
|
|
|
|
55 |
|
56 |
+
if 'outdated' in software_inventory_analysis.lower() or 'vulnerable' in software_inventory_analysis.lower():
|
57 |
+
recommendations.append("Update Software: Ensure that all installed software is up to date and free from known vulnerabilities.")
|
|
|
|
|
|
|
58 |
|
59 |
+
if 'vulnerable processes' in processes_analysis.lower() or 'unauthorized processes' in processes_analysis.lower():
|
60 |
+
recommendations.append("Review Running Processes: Regularly audit running processes and ensure that no unauthorized or vulnerable processes are running.")
|
|
|
|
|
|
|
61 |
|
62 |
return findings, recommendations
|
63 |
|
64 |
# Generate GDPR Compliance Report with advanced prompts for each section
|
65 |
def generate_gdpr_report(audit_data, company_name="Company Name", system_name="System Name"):
|
66 |
+
findings, recommendations = analyze_gdpr_compliance(audit_data)
|
67 |
|
68 |
+
report_content = f"""
|
69 |
GDPR Compliance Evaluation Report
|
70 |
|
71 |
Title: GDPR Compliance Evaluation Report
|
72 |
+
Date: {datetime.now().strftime('%Y-%m-%d')}
|
73 |
Prepared by: [Your Name]
|
74 |
For: {company_name}
|
75 |
|
|
|
78 |
Based on the system audit and analysis of data handling processes, this report provides findings, identifies compliance gaps,
|
79 |
and suggests recommendations to enhance GDPR adherence.
|
80 |
|
81 |
+
Key Findings:
|
82 |
+
|
83 |
System Information Analysis:
|
84 |
+
{findings['system_info']}
|
85 |
|
86 |
Disk Usage Analysis:
|
87 |
+
{findings['disk_usage']}
|
88 |
|
89 |
Network Info Analysis:
|
90 |
+
{findings['network_info']}
|
91 |
|
92 |
Security Measures Analysis:
|
93 |
+
{findings['security_measures']}
|
94 |
|
95 |
Running Processes Analysis:
|
96 |
+
{findings['running_processes']}
|
97 |
|
98 |
Software Inventory Analysis:
|
99 |
+
{findings['software_inventory']}
|
100 |
|
101 |
Recommendations:
|
102 |
+
{''.join(f'- {rec}\n' for rec in recommendations)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
+
Conclusion:
|
105 |
+
The analysis shows that while {company_name} has some strong protective measures in place, there are several areas for improvement. Implementing the suggested recommendations will enhance {company_name}'s compliance with GDPR and reduce potential risks of non-compliance.
|
|
|
|
|
|
|
106 |
|
107 |
+
References:
|
108 |
+
- GDPR Regulation (EU) 2016/679
|
109 |
+
- System Audit Report, {datetime.now().strftime('%Y-%m-%d')}
|
110 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
return report_content
|
113 |
|
|
|
136 |
csv_file = gr.File(label="Upload CSV file")
|
137 |
|
138 |
gdpr_compliance = gr.Textbox(lines=10, placeholder="GDPR Compliance Analysis...", label="GDPR Compliance Analysis")
|
|
|
139 |
|
140 |
def run_compliance_checks(csv_file):
|
141 |
if csv_file is None:
|
142 |
+
return "No file uploaded"
|
143 |
audit_data = analyze_csv_file(csv_file)
|
144 |
gdpr_report = generate_gdpr_report(audit_data)
|
145 |
+
return gdpr_report
|
|
|
146 |
|
147 |
check_compliance_btn = gr.Button("Run Compliance Checks")
|
148 |
+
check_compliance_btn.click(run_compliance_checks, inputs=[csv_file], outputs=[gdpr_compliance])
|
149 |
|
150 |
clear_btn = gr.Button("Clear")
|
151 |
+
clear_btn.click(lambda: "", None, [gdpr_compliance])
|
152 |
|
153 |
demo.launch(share=True)
|