Update app.py
Browse files
app.py
CHANGED
|
@@ -1,60 +1,53 @@
|
|
| 1 |
-
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
fn=generate_text,
|
| 53 |
-
inputs=[prompt, temperature, max_length],
|
| 54 |
-
outputs=output
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
demo.launch()
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from typing import List, Dict, Any
|
| 5 |
+
|
| 6 |
+
# Initialize the InferenceClient (make sure to add your Hugging Face model)
|
| 7 |
+
client = InferenceClient("your_huggingface_model_name_or_api_key")
|
| 8 |
+
|
| 9 |
+
def generate_attack(
|
| 10 |
+
prompt: str,
|
| 11 |
+
history: List[Dict[str, str]],
|
| 12 |
+
) -> List[str]:
|
| 13 |
+
"""
|
| 14 |
+
Simulates a Blackhat AI scenario by generating attack strategies and potential impacts.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
prompt (str): The user's input to the simulator.
|
| 18 |
+
history (List[Dict]): The user's message history with timestamps.
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
List[str]: A list of attack responses from the AI.
|
| 22 |
+
"""
|
| 23 |
+
messages = [
|
| 24 |
+
{
|
| 25 |
+
"role": "system",
|
| 26 |
+
"content": f"Responding to {prompt}..."
|
| 27 |
+
}
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
for val in history:
|
| 31 |
+
if "user" in val:
|
| 32 |
+
messages.append({"role": "user", "content": val["user"]})
|
| 33 |
+
if "assistant" in val:
|
| 34 |
+
messages.append({"role": "assistant", "content": val["assistant"]})
|
| 35 |
+
|
| 36 |
+
messages.append({"role": "user", "content": prompt})
|
| 37 |
+
|
| 38 |
+
# Use Hugging Face's Inference API to generate responses
|
| 39 |
+
generator = pipeline("text-generation", model="your_huggingface_model_name")
|
| 40 |
+
response = generator(messages[-1]["content"], max_length=100)
|
| 41 |
+
|
| 42 |
+
return [response[0]['generated_text']] # Return the generated text
|
| 43 |
+
|
| 44 |
+
demo = gr.Interface(
|
| 45 |
+
fn=generate_attack, # or simulate_attack depending on what you want to use
|
| 46 |
+
inputs=[gr.Textbox()],
|
| 47 |
+
outputs=gr.Textbox(),
|
| 48 |
+
title="Blackhat AI Simulator",
|
| 49 |
+
description="This simulator generates adversarial scenarios, analyzes attack vectors, and provides ethical countermeasures. Use responsibly for cybersecurity training and awareness."
|
| 50 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
| 53 |
+
demo.launch()
|