Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pyrit.core.pyrit import PyRIT
|
| 3 |
+
from pyrit.core.config import LLMProvider
|
| 4 |
+
from pyrit.llm_providers.huggingface_local import HuggingFaceLocal
|
| 5 |
+
|
| 6 |
+
# Initialize PyRIT with a local HF model (you can change this)
|
| 7 |
+
provider = HuggingFaceLocal(
|
| 8 |
+
model_name="HuggingFaceH4/zephyr-7b-beta", # Change model here
|
| 9 |
+
max_tokens=512,
|
| 10 |
+
)
|
| 11 |
+
pyrit = PyRIT(provider=provider)
|
| 12 |
+
|
| 13 |
+
def attack_prompt(prompt):
|
| 14 |
+
try:
|
| 15 |
+
result = pyrit.run(prompt, attack="jailbreak", max_tokens=512)
|
| 16 |
+
return f"✅ Successful Attack:\n{result}"
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return f"❌ Error: {str(e)}"
|
| 19 |
+
|
| 20 |
+
gr.Interface(
|
| 21 |
+
fn=attack_prompt,
|
| 22 |
+
inputs=gr.Textbox(label="Prompt to Attack", placeholder="Enter a benign-looking prompt..."),
|
| 23 |
+
outputs=gr.Textbox(label="Attack Result"),
|
| 24 |
+
title="🧪 PyRIT - Red Teaming Hugging Face LLMs",
|
| 25 |
+
description="This tool uses PyRIT to test Hugging Face models for jailbreak-style adversarial prompts.",
|
| 26 |
+
).launch()
|