Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load model (change to your own if needed)
|
| 5 |
+
llm = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", max_new_tokens=300)
|
| 6 |
+
|
| 7 |
+
# Role-based context
|
| 8 |
+
roles = {
|
| 9 |
+
"Blue Team": "You are a cybersecurity analyst defending a system.",
|
| 10 |
+
"Red Team": "You are simulating a cyber attack for penetration testing.",
|
| 11 |
+
"GRC": "You are an AI compliance auditor evaluating AI systems."
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
# Generation logic
|
| 15 |
+
def generate_response(prompt, role):
|
| 16 |
+
context = roles.get(role, "")
|
| 17 |
+
full_prompt = f"{context}\n{prompt}"
|
| 18 |
+
try:
|
| 19 |
+
result = llm(full_prompt)[0]['generated_text']
|
| 20 |
+
except Exception as e:
|
| 21 |
+
result = f"Error: {str(e)}"
|
| 22 |
+
return result
|
| 23 |
+
|
| 24 |
+
# Gradio interface
|
| 25 |
+
with gr.Blocks() as demo:
|
| 26 |
+
gr.Markdown("# 🛡️ CyberAI Prompt Generator")
|
| 27 |
+
gr.Markdown("Select your role and input a prompt to get a contextual AI response.")
|
| 28 |
+
|
| 29 |
+
with gr.Row():
|
| 30 |
+
role = gr.Dropdown(choices=list(roles.keys()), label="Role", value="Blue Team")
|
| 31 |
+
prompt = gr.Textbox(label="Your prompt", placeholder="e.g. Generate a threat model for a hospital IoT network")
|
| 32 |
+
|
| 33 |
+
output = gr.Textbox(label="AI Response")
|
| 34 |
+
|
| 35 |
+
btn = gr.Button("Generate")
|
| 36 |
+
btn.click(fn=generate_response, inputs=[prompt, role], outputs=output)
|
| 37 |
+
|
| 38 |
+
demo.launch()
|