Spaces:
Build error
Build error
Download app.py from deepugaur/prompt_projectapp: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/deepugaur/prompt_projectapp/resolve/main/app.py
- Command line
-
hf download hf://spaces/deepugaur/prompt_projectapp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/deepugaur/prompt_projectapp/resolve/main/app.py
1.09 kB
| 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*.") | |