Spaces:
Sleeping
Sleeping
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*.") | |