Consultus_Legis / app.py
michaelmc1618's picture
Update app.py
25824c1 verified
raw
history blame
5.07 kB
import os
os.system('pip install transformers')
os.system('pip install gradio')
os.system('pip install requests')
import requests
import gradio as gr
from huggingface_hub import InferenceClient
from transformers import pipeline
# Inference client for chat completion
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
# Different pipelines for different tasks
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
def respond(message, system_message, max_tokens, temperature, top_p):
messages = [{"role": "system", "content": system_message}]
messages.append({"role": "user", "content": message})
response = ""
for message in client.chat_completion(
messages,
max_tokens=max_tokens,
stream=True,
temperature=temperature,
top_p=top_p,
):
token = message.choices[0].delta.content
if token is not None:
response += token
return response
# GDPR Compliance Expert
def evaluate_gdpr_compliance(audit_data):
system_message = (
"You are an expert GDPR compliance officer. Assess the audit data for compliance with GDPR regulations. "
"Provide an analysis that identifies any compliance issues and suggestions for remediation. "
"Ensure a thorough evaluation of data processing, storage, and protection practices in line with GDPR requirements."
)
compliance_analysis = respond(audit_data, system_message, max_tokens=1024, temperature=0.7, top_p=0.95)
return compliance_analysis
# PCI Compliance Expert
def evaluate_pci_compliance(audit_data):
system_message = (
"You are an expert PCI compliance officer. Assess the audit data for compliance with PCI DSS regulations. "
"Provide an analysis that identifies any compliance issues and suggestions for remediation. "
"Ensure a thorough evaluation of payment card data security, storage, and processing practices in line with PCI requirements."
)
compliance_analysis = respond(audit_data, system_message, max_tokens=1024, temperature=0.7, top_p=0.95)
return compliance_analysis
# Custom CSS for the specified theme
custom_css = """
body {
background-color: #000000;
color: #ffffff;
font-family: Arial, sans-serif;
}
.gradio-container {
max-width: 1000px;
margin: 0 auto;
padding: 20px;
background-color: #000000;
border: 1px solid #e0e0e0;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.gr-button {
background-color: #000000 !important;
border-color: #ff0000 !important;
color: #ff0000 !important;
margin: 5px;
}
.gr-button:hover {
background-color: #ff0000 !important;
border-color: #ff0000 !important;
color: #000000 !important;
}
textarea.gr-textbox {
border-radius: 4px !important;
border: 2px solid #ff0000 !important;
background-color: #ffffff !important;
color: #000000 !important;
}
textarea.gr-textbox:focus {
border-color: #ff0000 !important;
outline: 0 !important;
box-shadow: 0 0 0 0.2rem rgba(255, 0, 0, 0.5) !important;
}
#flagging-button {
display: none;
}
footer {
display: none;
}
.chatbox .chat-container .chat-message {
background-color: #000000 !important;
color: #ffffff !important;
}
.chatbox .chat-container .chat-message-input {
background-color: #000000 !important;
color: #ffffff !important;
}
.gr-markdown {
background-color: #000000 !important;
color: #ffffff !important;
}
.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 {
color: #ffffff !important;
}
.score-box {
width: 60px;
height: 60px;
display: flex;
align-items: center
}
.label-hidden .gr-label {
display: none;
}
"""
# Gradio Interface
with gr.Blocks(css=custom_css) as demo:
with gr.Column():
gr.Markdown("# GDPR and PCI Compliance Evaluation\n### Provide Audit Data for Compliance Check")
audit_data = gr.Textbox(lines=5, placeholder="Enter audit data here...", label="Audit Data", elem_classes="label-hidden")
gdpr_compliance = gr.Textbox(lines=10, placeholder="GDPR Compliance Analysis...", label="GDPR Compliance Analysis", elem_classes="label-hidden")
pci_compliance = gr.Textbox(lines=10, placeholder="PCI Compliance Analysis...", label="PCI Compliance Analysis", elem_classes="label-hidden")
def run_compliance_checks(audit_data):
gdpr_analysis = evaluate_gdpr_compliance(audit_data)
pci_analysis = evaluate_pci_compliance(audit_data)
return gdpr_analysis, pci_analysis
check_compliance_btn = gr.Button("Run Compliance Checks")
check_compliance_btn.click(run_compliance_checks, inputs=[audit_data], outputs=[gdpr_compliance, pci_compliance])
clear_btn = gr.Button("Clear")
clear_btn.click(lambda: ("", "", ""), None, [audit_data, gdpr_compliance, pci_compliance])
demo.launch()