Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,14 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
# Load model & tokenizer
|
| 5 |
-
model_id = "
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 7 |
-
model = AutoModelForCausalLM.from_pretrained(model_id
|
| 8 |
|
| 9 |
# Create pipeline
|
| 10 |
-
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 11 |
|
| 12 |
-
# System instruction
|
| 13 |
SYSTEM_PROMPT = """You are Guardian AI, a friendly cybersecurity educator.
|
| 14 |
Your goal is to explain cybersecurity concepts in simple, engaging language with examples.
|
| 15 |
Always keep answers clear, short, and focused on security awareness.
|
|
@@ -18,14 +18,19 @@ Always keep answers clear, short, and focused on security awareness.
|
|
| 18 |
# Chat function
|
| 19 |
def chat(history, user_input):
|
| 20 |
prompt = SYSTEM_PROMPT + "\nUser: " + user_input + "\nGuardian AI:"
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
response = response.split("Guardian AI:")[-1].strip()
|
| 25 |
history.append((user_input, response))
|
| 26 |
return history, history
|
| 27 |
|
| 28 |
-
#
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
gr.Markdown("## 🛡️ Guardian AI – Cybersecurity Educator")
|
| 31 |
chatbot = gr.Chatbot()
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
# Load model & tokenizer
|
| 5 |
+
model_id = "google/gemma-2b-it"
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 8 |
|
| 9 |
# Create pipeline
|
| 10 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=-1)
|
| 11 |
|
| 12 |
+
# System instruction
|
| 13 |
SYSTEM_PROMPT = """You are Guardian AI, a friendly cybersecurity educator.
|
| 14 |
Your goal is to explain cybersecurity concepts in simple, engaging language with examples.
|
| 15 |
Always keep answers clear, short, and focused on security awareness.
|
|
|
|
| 18 |
# Chat function
|
| 19 |
def chat(history, user_input):
|
| 20 |
prompt = SYSTEM_PROMPT + "\nUser: " + user_input + "\nGuardian AI:"
|
| 21 |
+
result = generator(
|
| 22 |
+
prompt,
|
| 23 |
+
max_new_tokens=200,
|
| 24 |
+
do_sample=True,
|
| 25 |
+
temperature=0.7,
|
| 26 |
+
top_p=0.9
|
| 27 |
+
)[0]['generated_text']
|
| 28 |
|
| 29 |
+
response = result.split("Guardian AI:")[-1].strip()
|
|
|
|
| 30 |
history.append((user_input, response))
|
| 31 |
return history, history
|
| 32 |
|
| 33 |
+
# Gradio UI
|
| 34 |
with gr.Blocks() as demo:
|
| 35 |
gr.Markdown("## 🛡️ Guardian AI – Cybersecurity Educator")
|
| 36 |
chatbot = gr.Chatbot()
|