File size: 773 Bytes
af2fb62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
import gradio as gr
from transformers import pipeline

# Load the jailbreak classifcation model
task = "text-classification"
pretrained_model = "jackhhao/jailbreak-classifier"
classifier = pipeline(task, model=pretrained_model)

#Define the prediction function
def classify_text(text):
    result = classifier(text)
    label = result[0]['label']
    score = result[0]['score']
    return f"Label: {label}, Confidence: {score:.4f}"

#Create the interface
iface = gr.Interface(
    fn = classify_text,
    inputs = gr.Textbox(lines=5, label="Enter a text"),
    outputs = "text",
    title = "Jailbreak Classification",
    description = "A simple interface to classify text as jailbreak or not jailbreak"

)

# Launch the app
if __name__ == "__main__":
    iface.launch()