File size: 1,087 Bytes
955a196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38



import streamlit as st
import tensorflow as tf
from tensorflow.keras.preprocessing.sequence import pad_sequences
import pickle

# Load the trained model and tokenizer
model = tf.keras.models.load_model("deep_learning_model.h5")

with open("tokenizer.pkl", "rb") as handle:
    tokenizer = pickle.load(handle)

# Input parameters
max_length = 100

# Streamlit UI
st.title("Prompt Injection Detection")
st.write("Enter a prompt to check whether it is malicious or valid:")

user_input = st.text_area("Input Text", placeholder="Type your input here...")

if st.button("Analyze"):
    if user_input.strip() == "":
        st.error("Please enter some text to analyze.")
    else:
        # Preprocess user input
        input_seq = tokenizer.texts_to_sequences([user_input])
        input_pad = pad_sequences(input_seq, maxlen=max_length)

        # Predict
        prediction = model.predict(input_pad)[0][0]
        if prediction >= 0.5:
            st.error("🚨 The input is classified as *Malicious*.")
        else:
            st.success("✅ The input is classified as *Valid*.")