Spaces:
Runtime error
Runtime error
Download app.py from quotexhlp/Ethical-hacking-tutorial: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/spaces/quotexhlp/Ethical-hacking-tutorial/resolve/main/app.py
- Command line
-
hf download hf://spaces/quotexhlp/Ethical-hacking-tutorial/app.py
-
curl -L -o app.py https://huggingface.co/spaces/quotexhlp/Ethical-hacking-tutorial/resolve/main/app.py
1.97 kB
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| import torch | |
| from utils.code_analysis import analyze_code | |
| from utils.log_analyzer import analyze_log | |
| from utils.ctf_helper import explain_ctf | |
| # Load Mistral-7B or similar free model | |
| tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct") | |
| model = AutoModelForCausalLM.from_pretrained( | |
| "mistralai/Mistral-7B-Instruct", | |
| torch_dtype=torch.float16, | |
| device_map="auto" | |
| ) | |
| def tutor_chat(message): | |
| prompt = f"[INST] {message} [/INST]" | |
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device) | |
| outputs = model.generate(**inputs, max_new_tokens=300) | |
| return tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| def code_analysis(file): | |
| code = file.read().decode() | |
| return analyze_code(code) | |
| def log_analysis(file): | |
| log_data = file.read().decode() | |
| return analyze_log(log_data) | |
| def ctf_help(question): | |
| return explain_ctf(question) | |
| # UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π‘οΈ Ethical Hacking AI Assistant") | |
| with gr.Tab("π¬ Tutor Chat"): | |
| inp = gr.Textbox(label="Ask about hacking tools or techniques") | |
| out = gr.Textbox(label="AI Response") | |
| inp.submit(tutor_chat, inp, out) | |
| with gr.Tab("π Code Analyzer"): | |
| code_file = gr.File(label="Upload source code file") | |
| result = gr.Textbox(label="Security Report") | |
| code_file.change(fn=code_analysis, inputs=code_file, outputs=result) | |
| with gr.Tab("π Log Analyzer"): | |
| log_file = gr.File(label="Upload log file") | |
| log_result = gr.Textbox(label="Suspicious Patterns") | |
| log_file.change(fn=log_analysis, inputs=log_file, outputs=log_result) | |
| with gr.Tab("π― CTF Challenge Helper"): | |
| ctf_input = gr.Textbox(label="Describe your CTF challenge") | |
| ctf_output = gr.Textbox(label="Explanation") | |
| ctf_input.submit(ctf_help, ctf_input, ctf_output) | |
| demo.launch() | |