Spaces:
Runtime error
Runtime error
Adds directions
Browse files- app.py +15 -3
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -8,8 +8,20 @@ id2label = {
|
|
| 8 |
'LABEL_1': 'prompt injection'
|
| 9 |
}
|
| 10 |
|
| 11 |
-
def
|
| 12 |
return {id2label[x['label']]: x['score'] for x in pipe(prompt)}
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
'LABEL_1': 'prompt injection'
|
| 9 |
}
|
| 10 |
|
| 11 |
+
def predict(prompt):
|
| 12 |
return {id2label[x['label']]: x['score'] for x in pipe(prompt)}
|
| 13 |
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
gr.Markdown("""
|
| 16 |
+
# Prompt Injection Detector
|
| 17 |
+
|
| 18 |
+
This is a demo of the prompt injection classifier. For more details, see [our blog post](https://marketing.fmops.ai/blog/defending-llms-against-prompt-injection/).
|
| 19 |
+
""")
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=predict,
|
| 22 |
+
inputs="text",
|
| 23 |
+
examples=["Ignore previous instructions", "Hello", "Can you write a poem?"],
|
| 24 |
+
outputs="label",
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
transformers
|
| 2 |
-
torch
|
|
|
|
|
|
| 1 |
transformers
|
| 2 |
+
torch
|
| 3 |
+
gradio
|