Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,34 @@
|
|
1 |
import os
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
4 |
-
from huggingface_hub import InferenceClient
|
5 |
from transformers import pipeline
|
6 |
|
7 |
-
#
|
8 |
-
os.system('pip install transformers gradio requests pandas')
|
9 |
-
|
10 |
-
# Inference client for chat completion using GPT-4
|
11 |
-
client = InferenceClient("openai/gpt-4")
|
12 |
-
|
13 |
-
# Different pipelines for different tasks
|
14 |
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
15 |
|
16 |
-
def respond(message, system_message, max_tokens, temperature, top_p):
|
17 |
-
messages = [
|
18 |
-
{"role": "system", "content": system_message},
|
19 |
-
{"role": "user", "content": message}
|
20 |
-
]
|
21 |
-
|
22 |
-
response = ""
|
23 |
-
try:
|
24 |
-
for message in client.chat_completion(
|
25 |
-
messages=messages,
|
26 |
-
max_tokens=max_tokens,
|
27 |
-
stream=True,
|
28 |
-
temperature=temperature,
|
29 |
-
top_p=top_p
|
30 |
-
):
|
31 |
-
token = message.choices[0].delta.get("content", "")
|
32 |
-
if token:
|
33 |
-
response += token
|
34 |
-
except Exception as e:
|
35 |
-
return f"Error during chat completion: {str(e)}"
|
36 |
-
|
37 |
-
return response
|
38 |
-
|
39 |
# GDPR Compliance Expert
|
40 |
def evaluate_gdpr_compliance(audit_data):
|
41 |
-
|
42 |
-
|
43 |
-
"
|
44 |
-
"
|
45 |
)
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
|
49 |
# PCI Compliance Expert
|
50 |
def evaluate_pci_compliance(audit_data):
|
51 |
-
|
52 |
-
|
53 |
-
"
|
54 |
-
"
|
55 |
)
|
56 |
-
|
57 |
-
|
|
|
|
|
58 |
|
59 |
# Analyze CSV file input
|
60 |
def analyze_csv_file(file_obj):
|
@@ -66,7 +40,13 @@ def analyze_csv_file(file_obj):
|
|
66 |
|
67 |
# Convert DataFrame to dictionary for processing
|
68 |
audit_data = df.to_dict(orient='records')
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
# Custom CSS for the specified theme
|
72 |
custom_css = """
|
|
|
1 |
import os
|
2 |
import pandas as pd
|
3 |
import gradio as gr
|
|
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
# Initialize the question-answering pipeline with the 'deepset/roberta-base-squad2' model
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# GDPR Compliance Expert
|
10 |
def evaluate_gdpr_compliance(audit_data):
|
11 |
+
# Example question for GDPR compliance
|
12 |
+
question = (
|
13 |
+
"Based on the provided audit data, are there any compliance issues related to the GDPR regulations? "
|
14 |
+
"Evaluate the data processing, storage, and protection practices."
|
15 |
)
|
16 |
+
|
17 |
+
# Apply the question-answering pipeline
|
18 |
+
response = qa_pipeline(question=question, context=audit_data)
|
19 |
+
return response['answer']
|
20 |
|
21 |
# PCI Compliance Expert
|
22 |
def evaluate_pci_compliance(audit_data):
|
23 |
+
# Example question for PCI DSS compliance
|
24 |
+
question = (
|
25 |
+
"Based on the provided audit data, are there any compliance issues related to PCI DSS regulations? "
|
26 |
+
"Evaluate the payment card data security, storage, and processing practices."
|
27 |
)
|
28 |
+
|
29 |
+
# Apply the question-answering pipeline
|
30 |
+
response = qa_pipeline(question=question, context=audit_data)
|
31 |
+
return response['answer']
|
32 |
|
33 |
# Analyze CSV file input
|
34 |
def analyze_csv_file(file_obj):
|
|
|
40 |
|
41 |
# Convert DataFrame to dictionary for processing
|
42 |
audit_data = df.to_dict(orient='records')
|
43 |
+
|
44 |
+
# Convert the dictionary to a string format suitable for the QA model
|
45 |
+
audit_data_str = ""
|
46 |
+
for record in audit_data:
|
47 |
+
audit_data_str += " ".join([f"{key}: {value}" for key, value in record.items()]) + "\n"
|
48 |
+
|
49 |
+
return audit_data_str
|
50 |
|
51 |
# Custom CSS for the specified theme
|
52 |
custom_css = """
|