Spaces:
Running
Running
Canstralian
commited on
Commit
•
58412c3
1
Parent(s):
286fe34
Update app.py
Browse files
app.py
CHANGED
@@ -6,27 +6,39 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
6 |
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
message,
|
12 |
history: list[tuple[str, str]],
|
13 |
system_message,
|
14 |
max_tokens,
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
|
|
20 |
for val in history:
|
21 |
if val[0]:
|
22 |
messages.append({"role": "user", "content": val[0]})
|
23 |
if val[1]:
|
24 |
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
-
|
|
|
27 |
|
|
|
28 |
response = ""
|
29 |
|
|
|
30 |
for message in client.chat_completion(
|
31 |
messages,
|
32 |
max_tokens=max_tokens,
|
@@ -39,25 +51,31 @@ def respond(
|
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
-
|
43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
-
"""
|
45 |
demo = gr.ChatInterface(
|
46 |
-
|
47 |
additional_inputs=[
|
48 |
-
gr.Textbox(
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
gr.Slider(
|
52 |
minimum=0.1,
|
53 |
maximum=1.0,
|
54 |
-
value=0.
|
55 |
step=0.05,
|
56 |
label="Top-p (nucleus sampling)",
|
57 |
),
|
58 |
],
|
|
|
|
|
|
|
|
|
59 |
)
|
60 |
|
61 |
-
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
|
|
6 |
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
+
def simulate_attack(
|
10 |
+
prompt,
|
|
|
11 |
history: list[tuple[str, str]],
|
12 |
system_message,
|
13 |
max_tokens,
|
14 |
temperature,
|
15 |
top_p,
|
16 |
):
|
17 |
+
"""
|
18 |
+
Simulates a Blackhat AI scenario by generating attack strategies, potential impacts, and ethical countermeasures.
|
19 |
+
"""
|
20 |
+
# Build the system message to define the simulator's behavior
|
21 |
+
messages = [
|
22 |
+
{
|
23 |
+
"role": "system",
|
24 |
+
"content": system_message,
|
25 |
+
}
|
26 |
+
]
|
27 |
|
28 |
+
# Include user and assistant message history
|
29 |
for val in history:
|
30 |
if val[0]:
|
31 |
messages.append({"role": "user", "content": val[0]})
|
32 |
if val[1]:
|
33 |
messages.append({"role": "assistant", "content": val[1]})
|
34 |
|
35 |
+
# Add the current user prompt
|
36 |
+
messages.append({"role": "user", "content": prompt})
|
37 |
|
38 |
+
# Initialize the response variable
|
39 |
response = ""
|
40 |
|
41 |
+
# Stream the AI's response from the inference API
|
42 |
for message in client.chat_completion(
|
43 |
messages,
|
44 |
max_tokens=max_tokens,
|
|
|
51 |
response += token
|
52 |
yield response
|
53 |
|
54 |
+
# Define the Gradio ChatInterface with security-focused configuration
|
|
|
|
|
55 |
demo = gr.ChatInterface(
|
56 |
+
simulate_attack,
|
57 |
additional_inputs=[
|
58 |
+
gr.Textbox(
|
59 |
+
value=(
|
60 |
+
"You are an AI simulator for cybersecurity training, designed to generate attack scenarios, analyze their impacts, and suggest countermeasures."
|
61 |
+
),
|
62 |
+
label="System message",
|
63 |
+
),
|
64 |
+
gr.Slider(minimum=1, maximum=2048, value=1024, step=1, label="Max new tokens"),
|
65 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=1.0, step=0.1, label="Temperature"),
|
66 |
gr.Slider(
|
67 |
minimum=0.1,
|
68 |
maximum=1.0,
|
69 |
+
value=0.9,
|
70 |
step=0.05,
|
71 |
label="Top-p (nucleus sampling)",
|
72 |
),
|
73 |
],
|
74 |
+
title="Blackhat AI Simulator",
|
75 |
+
description=(
|
76 |
+
"This simulator generates adversarial scenarios, analyzes attack vectors, and provides ethical countermeasures. Use responsibly for cybersecurity training and awareness."
|
77 |
+
),
|
78 |
)
|
79 |
|
|
|
80 |
if __name__ == "__main__":
|
81 |
+
demo.launch()
|