Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
import tensorflow as tf
|
6 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
7 |
+
import pickle
|
8 |
+
|
9 |
+
# Load the trained model and tokenizer
|
10 |
+
model = tf.keras.models.load_model("deep_learning_model.h5")
|
11 |
+
|
12 |
+
with open("tokenizer.pkl", "rb") as handle:
|
13 |
+
tokenizer = pickle.load(handle)
|
14 |
+
|
15 |
+
# Input parameters
|
16 |
+
max_length = 100
|
17 |
+
|
18 |
+
# Streamlit UI
|
19 |
+
st.title("Prompt Injection Detection")
|
20 |
+
st.write("Enter a prompt to check whether it is malicious or valid:")
|
21 |
+
|
22 |
+
user_input = st.text_area("Input Text", placeholder="Type your input here...")
|
23 |
+
|
24 |
+
if st.button("Analyze"):
|
25 |
+
if user_input.strip() == "":
|
26 |
+
st.error("Please enter some text to analyze.")
|
27 |
+
else:
|
28 |
+
# Preprocess user input
|
29 |
+
input_seq = tokenizer.texts_to_sequences([user_input])
|
30 |
+
input_pad = pad_sequences(input_seq, maxlen=max_length)
|
31 |
+
|
32 |
+
# Predict
|
33 |
+
prediction = model.predict(input_pad)[0][0]
|
34 |
+
if prediction >= 0.5:
|
35 |
+
st.error("🚨 The input is classified as *Malicious*.")
|
36 |
+
else:
|
37 |
+
st.success("✅ The input is classified as *Valid*.")
|