Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,143 @@
|
|
1 |
import os
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
4 |
-
from
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
def
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
#
|
22 |
-
def
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
# Analyze CSV file input
|
34 |
def analyze_csv_file(file_obj):
|
35 |
# Read the CSV file into a pandas DataFrame
|
36 |
try:
|
@@ -41,99 +148,29 @@ def analyze_csv_file(file_obj):
|
|
41 |
# Convert DataFrame to dictionary for processing
|
42 |
audit_data = df.to_dict(orient='records')
|
43 |
|
44 |
-
# Convert the dictionary to a
|
45 |
-
|
46 |
for record in audit_data:
|
47 |
-
|
48 |
|
49 |
-
return
|
50 |
-
|
51 |
-
# Custom CSS for the specified theme
|
52 |
-
custom_css = """
|
53 |
-
body {
|
54 |
-
background-color: #000000;
|
55 |
-
color: #ffffff;
|
56 |
-
font-family: Arial, sans-serif;
|
57 |
-
}
|
58 |
-
.gradio-container {
|
59 |
-
max-width: 1000px;
|
60 |
-
margin: 0 auto;
|
61 |
-
padding: 20px;
|
62 |
-
background-color: #000000;
|
63 |
-
border: 1px solid #e0e0e0;
|
64 |
-
border-radius: 8px;
|
65 |
-
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
66 |
-
}
|
67 |
-
.gr-button {
|
68 |
-
background-color: #000000 !important;
|
69 |
-
border-color: #ff0000 !important;
|
70 |
-
color: #ff0000 !important;
|
71 |
-
margin: 5px;
|
72 |
-
}
|
73 |
-
.gr-button:hover {
|
74 |
-
background-color: #ff0000 !important;
|
75 |
-
border-color: #ff0000 !important;
|
76 |
-
color: #000000 !important;
|
77 |
-
}
|
78 |
-
textarea.gr-textbox {
|
79 |
-
border-radius: 4px !important;
|
80 |
-
border: 2px solid #ff0000 !important;
|
81 |
-
background-color: #ffffff !important;
|
82 |
-
color: #000000 !important;
|
83 |
-
}
|
84 |
-
textarea.gr-textbox:focus {
|
85 |
-
border-color: #ff0000 !important;
|
86 |
-
outline: 0 !important;
|
87 |
-
box-shadow: 0 0 0 0.2rem rgba(255, 0, 0, 0.5) !important;
|
88 |
-
}
|
89 |
-
#flagging-button {
|
90 |
-
display: none;
|
91 |
-
}
|
92 |
-
footer {
|
93 |
-
display: none;
|
94 |
-
}
|
95 |
-
.chatbox .chat-container .chat-message {
|
96 |
-
background-color: #000000 !important;
|
97 |
-
color: #ffffff !important;
|
98 |
-
}
|
99 |
-
.chatbox .chat-container .chat-message-input {
|
100 |
-
background-color: #000000 !important;
|
101 |
-
color: #ffffff !important;
|
102 |
-
}
|
103 |
-
.gr-markdown {
|
104 |
-
background-color: #000000 !important;
|
105 |
-
color: #ffffff !important;
|
106 |
-
}
|
107 |
-
.gr-markdown h1, .gr-markdown h2, .gr-markdown h3, .gr-markdown h4, .gr-markdown h5, .gr-markdown h6, .gr-markdown p, .gr-markdown ul, .gr-markdown ol, .gr-markdown li {
|
108 |
-
color: #ffffff !important;
|
109 |
-
}
|
110 |
-
.score-box {
|
111 |
-
width: 60px;
|
112 |
-
height: 60px;
|
113 |
-
display: flex;
|
114 |
-
align-items: center
|
115 |
-
}
|
116 |
-
.label-hidden .gr-label {
|
117 |
-
display: none;
|
118 |
-
}
|
119 |
-
"""
|
120 |
|
121 |
# Gradio Interface
|
122 |
-
with gr.Blocks(
|
123 |
with gr.Column():
|
124 |
gr.Markdown("# GDPR and PCI Compliance Evaluation\n### Upload Audit Data in CSV Format")
|
125 |
csv_file = gr.File(label="Upload CSV file")
|
126 |
|
127 |
-
gdpr_compliance = gr.Textbox(lines=10, placeholder="GDPR Compliance Analysis...", label="GDPR Compliance Analysis"
|
128 |
-
pci_compliance = gr.Textbox(lines=10, placeholder="PCI Compliance Analysis...", label="PCI Compliance Analysis"
|
129 |
|
130 |
def run_compliance_checks(csv_file):
|
131 |
if csv_file is None:
|
132 |
return "No file uploaded", "No file uploaded"
|
133 |
audit_data = analyze_csv_file(csv_file)
|
134 |
-
|
135 |
-
|
136 |
-
return
|
137 |
|
138 |
check_compliance_btn = gr.Button("Run Compliance Checks")
|
139 |
check_compliance_btn.click(run_compliance_checks, inputs=[csv_file], outputs=[gdpr_compliance, pci_compliance])
|
|
|
1 |
import os
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
4 |
+
from datetime import datetime
|
5 |
|
6 |
+
# Function to analyze audit data for GDPR compliance
|
7 |
+
def analyze_data_for_gdpr(audit_data):
|
8 |
+
findings = {
|
9 |
+
"system_info": {
|
10 |
+
"os_version": audit_data.get("os_version", "Unknown"),
|
11 |
+
"architecture": audit_data.get("architecture", "Unknown"),
|
12 |
+
"memory": audit_data.get("memory", "Unknown")
|
13 |
+
},
|
14 |
+
"disk_usage": {
|
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 findings["security_measures"]["encryption"]:
|
30 |
+
recommendations.append("Implement Encryption: Ensure that both stored and transmitted data are encrypted.")
|
31 |
+
if not findings["security_measures"]["data_anonymization"]:
|
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 |
+
"firewall": audit_data.get("pci_security", {}).get("firewall", False),
|
41 |
+
"antivirus": audit_data.get("pci_security", {}).get("antivirus", False),
|
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 findings["pci_security"]["firewall"]:
|
53 |
+
recommendations.append("Implement Firewall: Ensure that a firewall is in place to protect the network.")
|
54 |
+
if not findings["card_data_security"]["encryption"]:
|
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 = f"""
|
64 |
+
GDPR Compliance Evaluation Report
|
65 |
+
|
66 |
+
Title: GDPR Compliance Evaluation Report
|
67 |
+
Date: {datetime.now().strftime('%Y-%m-%d')}
|
68 |
+
Prepared by: [Your Name]
|
69 |
+
For: {company_name}
|
70 |
+
|
71 |
+
Executive Summary:
|
72 |
+
This report evaluates the compliance of {company_name} with the General Data Protection Regulation (GDPR).
|
73 |
+
Based on the system audit and analysis of data handling processes, this report provides findings, identifies compliance gaps,
|
74 |
+
and suggests recommendations to enhance GDPR adherence.
|
75 |
+
|
76 |
+
Findings:
|
77 |
+
System Information:
|
78 |
+
- OS Version: {findings['system_info']['os_version']}
|
79 |
+
- Architecture: {findings['system_info']['architecture']}
|
80 |
+
- Memory: {findings['system_info']['memory']}
|
81 |
+
|
82 |
+
Disk Usage:
|
83 |
+
- Usage Percent: {findings['disk_usage']['usage_percent']}
|
84 |
+
|
85 |
+
Network Info:
|
86 |
+
- Interfaces: {', '.join(findings['network_info']['interfaces'])}
|
87 |
+
|
88 |
+
Security Measures:
|
89 |
+
- Encryption: {"Yes" if findings['security_measures']['encryption'] else "No"}
|
90 |
+
- Data Anonymization: {"Yes" if findings['security_measures']['data_anonymization'] else "No"}
|
91 |
+
|
92 |
+
Running Processes:
|
93 |
+
- Processes: {', '.join(findings['running_processes'])}
|
94 |
+
|
95 |
+
Software Inventory:
|
96 |
+
- Installed Software: {', '.join(findings['software_inventory'])}
|
97 |
+
|
98 |
+
Recommendations:
|
99 |
+
{''.join(f'- {rec}\n' for rec in recommendations)}
|
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 = f"""
|
109 |
+
PCI Compliance Evaluation Report
|
110 |
+
|
111 |
+
Title: PCI Compliance Evaluation Report
|
112 |
+
Date: {datetime.now().strftime('%Y-%m-%d')}
|
113 |
+
Prepared by: [Your Name]
|
114 |
+
For: {company_name}
|
115 |
+
|
116 |
+
Executive Summary:
|
117 |
+
This report evaluates the compliance of {company_name} with the Payment Card Industry Data Security Standard (PCI DSS).
|
118 |
+
Based on the system audit and analysis of data handling processes, this report provides findings, identifies compliance gaps,
|
119 |
+
and suggests recommendations to enhance PCI DSS adherence.
|
120 |
+
|
121 |
+
Findings:
|
122 |
+
PCI Security Measures:
|
123 |
+
- Firewall: {"Yes" if findings['pci_security']['firewall'] else "No"}
|
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 |
+
- Encryption: {"Yes" if findings['card_data_security']['encryption'] else "No"}
|
129 |
+
- Storage Protection: {"Yes" if findings['card_data_security']['storage_protection'] else "No"}
|
130 |
+
|
131 |
+
Network Configurations:
|
132 |
+
- Configurations: {', '.join(findings['network_configurations'])}
|
133 |
+
|
134 |
+
Recommendations:
|
135 |
+
{''.join(f'- {rec}\n' for rec in recommendations)}
|
136 |
+
"""
|
137 |
+
|
138 |
+
return report_content
|
139 |
|
140 |
+
# Analyze CSV file input and convert it to JSON-like dictionary for processing
|
141 |
def analyze_csv_file(file_obj):
|
142 |
# Read the CSV file into a pandas DataFrame
|
143 |
try:
|
|
|
148 |
# Convert DataFrame to dictionary for processing
|
149 |
audit_data = df.to_dict(orient='records')
|
150 |
|
151 |
+
# Convert the dictionary to a JSON-like structure suitable for analysis
|
152 |
+
audit_data_json = {}
|
153 |
for record in audit_data:
|
154 |
+
audit_data_json.update(record)
|
155 |
|
156 |
+
return audit_data_json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
# Gradio Interface
|
159 |
+
with gr.Blocks() as demo:
|
160 |
with gr.Column():
|
161 |
gr.Markdown("# GDPR and PCI Compliance Evaluation\n### Upload Audit Data in CSV Format")
|
162 |
csv_file = gr.File(label="Upload CSV file")
|
163 |
|
164 |
+
gdpr_compliance = gr.Textbox(lines=10, placeholder="GDPR Compliance Analysis...", label="GDPR Compliance Analysis")
|
165 |
+
pci_compliance = gr.Textbox(lines=10, placeholder="PCI Compliance Analysis...", label="PCI Compliance Analysis")
|
166 |
|
167 |
def run_compliance_checks(csv_file):
|
168 |
if csv_file is None:
|
169 |
return "No file uploaded", "No file uploaded"
|
170 |
audit_data = analyze_csv_file(csv_file)
|
171 |
+
gdpr_report = generate_gdpr_report(audit_data)
|
172 |
+
pci_report = generate_pci_report(audit_data)
|
173 |
+
return gdpr_report, pci_report
|
174 |
|
175 |
check_compliance_btn = gr.Button("Run Compliance Checks")
|
176 |
check_compliance_btn.click(run_compliance_checks, inputs=[csv_file], outputs=[gdpr_compliance, pci_compliance])
|