Canstralian
commited on
Update pentest_ai_streamlit.py
Browse files- pentest_ai_streamlit.py +33 -46
pentest_ai_streamlit.py
CHANGED
@@ -1,49 +1,36 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
|
|
3 |
|
4 |
-
|
5 |
-
MODEL_NAME = "Canstralian/pentest_ai"
|
6 |
-
|
7 |
-
@st.cache_resource
|
8 |
def load_model():
|
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 |
-
|
39 |
-
example_query = "How do I scan a network for open ports?"
|
40 |
-
with st.spinner("Generating response for example query..."):
|
41 |
-
example_response = pentest_ai(example_query, max_length=150, num_return_sequences=1)[0]['generated_text']
|
42 |
-
|
43 |
-
st.subheader("Example Query:")
|
44 |
-
st.write(example_query)
|
45 |
-
st.subheader("AI Response:")
|
46 |
-
st.write(example_response)
|
47 |
-
|
48 |
-
# Instructions for the user
|
49 |
-
st.info("Note: This AI model provides general advice. Always ensure you're testing on systems you have permission to, and follow legal and ethical guidelines.")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
|
5 |
+
@st.cache(allow_output_mutation=True)
|
|
|
|
|
|
|
6 |
def load_model():
|
7 |
+
model_path = "Canstralian/pentest_ai"
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
model_path,
|
10 |
+
torch_dtype=torch.float16,
|
11 |
+
device_map="auto",
|
12 |
+
load_in_4bit=False,
|
13 |
+
load_in_8bit=True,
|
14 |
+
trust_remote_code=True,
|
15 |
+
)
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
17 |
+
return model, tokenizer
|
18 |
+
|
19 |
+
def generate_text(model, tokenizer, instruction):
|
20 |
+
tokens = tokenizer.encode(instruction, return_tensors='pt').to('cuda')
|
21 |
+
generated_tokens = model.generate(
|
22 |
+
tokens,
|
23 |
+
max_length=1024,
|
24 |
+
top_p=1.0,
|
25 |
+
temperature=0.5,
|
26 |
+
top_k=50
|
27 |
+
)
|
28 |
+
return tokenizer.decode(generated_tokens[0], skip_special_tokens=True)
|
29 |
+
|
30 |
+
model, tokenizer = load_model()
|
31 |
+
|
32 |
+
st.title("Penetration Testing AI Assistant")
|
33 |
+
instruction = st.text_area("Enter your question:")
|
34 |
+
if st.button("Generate"):
|
35 |
+
response = generate_text(model, tokenizer, instruction)
|
36 |
+
st.write(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|