quotexhlp commited on
Commit
fa80d08
·
verified ·
1 Parent(s): 2695a4f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+ from utils.code_analysis import analyze_code
5
+ from utils.log_analyzer import analyze_log
6
+ from utils.ctf_helper import explain_ctf
7
+
8
+ # Load Mistral-7B or similar free model
9
+ tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct")
10
+ model = AutoModelForCausalLM.from_pretrained(
11
+ "mistralai/Mistral-7B-Instruct",
12
+ torch_dtype=torch.float16,
13
+ device_map="auto"
14
+ )
15
+
16
+ def tutor_chat(message):
17
+ prompt = f"[INST] {message} [/INST]"
18
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
19
+ outputs = model.generate(**inputs, max_new_tokens=300)
20
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
21
+
22
+ def code_analysis(file):
23
+ code = file.read().decode()
24
+ return analyze_code(code)
25
+
26
+ def log_analysis(file):
27
+ log_data = file.read().decode()
28
+ return analyze_log(log_data)
29
+
30
+ def ctf_help(question):
31
+ return explain_ctf(question)
32
+
33
+ # UI
34
+ with gr.Blocks() as demo:
35
+ gr.Markdown("# 🛡️ Ethical Hacking AI Assistant")
36
+
37
+ with gr.Tab("💬 Tutor Chat"):
38
+ inp = gr.Textbox(label="Ask about hacking tools or techniques")
39
+ out = gr.Textbox(label="AI Response")
40
+ inp.submit(tutor_chat, inp, out)
41
+
42
+ with gr.Tab("📄 Code Analyzer"):
43
+ code_file = gr.File(label="Upload source code file")
44
+ result = gr.Textbox(label="Security Report")
45
+ code_file.change(fn=code_analysis, inputs=code_file, outputs=result)
46
+
47
+ with gr.Tab("📜 Log Analyzer"):
48
+ log_file = gr.File(label="Upload log file")
49
+ log_result = gr.Textbox(label="Suspicious Patterns")
50
+ log_file.change(fn=log_analysis, inputs=log_file, outputs=log_result)
51
+
52
+ with gr.Tab("🎯 CTF Challenge Helper"):
53
+ ctf_input = gr.Textbox(label="Describe your CTF challenge")
54
+ ctf_output = gr.Textbox(label="Explanation")
55
+ ctf_input.submit(ctf_help, ctf_input, ctf_output)
56
+
57
+ demo.launch()