File size: 4,739 Bytes
f1f855e 2373c44 f1f855e c16688b 2373c44 f1f855e 2373c44 c16688b 2373c44 c16688b 2373c44 ee0accd 2373c44 c16688b 2373c44 c16688b 2373c44 c16688b 2373c44 c16688b f1f855e 2373c44 f1f855e 2373c44 67ebc16 2373c44 67ebc16 f1f855e 2373c44 0b4d051 2373c44 0b4d051 2373c44 0b4d051 c16688b 2373c44 0b4d051 2373c44 f1f855e 2373c44 f1f855e 2373c44 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
import gradio as gr
import requests
import os
# Configuration
MODEL_REPO = "AlicanKiraz0/Cybersecurity-BaronLLM_Offensive_Security_LLM_Q6_K_GGUF"
API_URL = f"https://api-inference.huggingface.co/models/{MODEL_REPO}"
HF_TOKEN = os.environ.get("HF_TOKEN", "")
headers = {
"Authorization": f"Bearer {HF_TOKEN}",
"Content-Type": "application/json"
}
def query_model(payload):
"""
Query the model using Hugging Face Inference API
"""
try:
response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
return {"error": f"API request failed: {str(e)}"}
except Exception as e:
return {"error": f"Unexpected error: {str(e)}"}
def generate_response(prompt, max_tokens=150, temperature=0.7):
"""
Generate response using the model
"""
if not prompt.strip():
return "Please enter a prompt."
payload = {
"inputs": prompt,
"parameters": {
"max_new_tokens": max_tokens,
"temperature": temperature,
"top_p": 0.9,
"do_sample": True,
"return_full_text": False
}
}
result = query_model(payload)
if "error" in result:
error_msg = result["error"]
if "loading" in error_msg.lower():
return f"Model is currently loading. Please wait a moment and try again.\n\nError details: {error_msg}"
return f"Error: {error_msg}"
if isinstance(result, list) and len(result) > 0:
if "generated_text" in result[0]:
return result[0]["generated_text"]
elif "text" in result[0]:
return result[0]["text"]
return "No response generated. Please try again."
# Create Gradio interface
with gr.Blocks(title="Cybersecurity BaronLLM", theme=gr.themes.Soft()) as demo:
gr.Markdown("""
# π Cybersecurity BaronLLM
**Offensive Security Language Model**
This interface uses the Cybersecurity BaronLLM model via Hugging Face Inference API.
""")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### Configuration")
max_tokens = gr.Slider(
minimum=32,
maximum=512,
value=150,
step=32,
label="Max Tokens",
info="Maximum length of response"
)
temperature = gr.Slider(
minimum=0.1,
maximum=1.0,
value=0.7,
step=0.1,
label="Temperature",
info="Higher values = more creative, lower values = more focused"
)
gr.Markdown("""
### Example Prompts
- Explain SQL injection techniques
- What are common penetration testing methodologies?
- How to detect XSS attacks?
- Describe network security principles
""")
with gr.Column(scale=2):
prompt = gr.Textbox(
label="Enter your cybersecurity question or prompt:",
placeholder="Explain SQL injection techniques and prevention methods...",
lines=5,
max_lines=10
)
generate_btn = gr.Button("π Generate Response", variant="primary", size="lg")
output = gr.Textbox(
label="Model Response",
lines=8,
show_copy_button=True
)
# Examples
examples = gr.Examples(
examples=[
["What are the most common web application vulnerabilities and how can they be exploited?"],
["Explain the difference between white hat, black hat, and gray hat hackers."],
["Describe the steps involved in a penetration testing engagement."],
["How does a buffer overflow attack work and what are modern defenses against it?"],
["What are the key components of a cybersecurity risk assessment?"]
],
inputs=prompt,
outputs=output,
fn=generate_response,
cache_examples=False
)
# Event handlers
generate_btn.click(
fn=generate_response,
inputs=[prompt, max_tokens, temperature],
outputs=output
)
# Also generate on Enter key
prompt.submit(
fn=generate_response,
inputs=[prompt, max_tokens, temperature],
outputs=output
)
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False
) |