Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
MODEL_NAME = "ZySec-7B"
|
6 |
+
|
7 |
+
@st.cache_resource()
|
8 |
+
def load_model():
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto")
|
11 |
+
return tokenizer, model
|
12 |
+
|
13 |
+
tokenizer, model = load_model()
|
14 |
+
|
15 |
+
st.title("🔐 Cybersecurity Chatbot")
|
16 |
+
|
17 |
+
user_input = st.text_input("Ask a cybersecurity question:")
|
18 |
+
|
19 |
+
if user_input:
|
20 |
+
input_ids = tokenizer.encode(user_input, return_tensors="pt").to("cuda")
|
21 |
+
output = model.generate(input_ids, max_length=200)
|
22 |
+
response = tokenizer.decode(output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
23 |
+
|
24 |
+
st.write("🤖", response)
|