Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,88 +1,96 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from llama_cpp import Llama
|
| 3 |
|
| 4 |
-
|
| 5 |
-
st.
|
| 6 |
|
|
|
|
| 7 |
st.markdown("""
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
return Llama.from_pretrained(
|
| 25 |
repo_id=repo_id,
|
| 26 |
filename=filename,
|
| 27 |
-
n_ctx=2048,
|
| 28 |
)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
if model_choice == "Generalist 🤖":
|
| 32 |
-
st.sidebar.markdown("""
|
| 33 |
-
**Best for:**
|
| 34 |
-
- Creative writing
|
| 35 |
-
- Brainstorming tools or strategies
|
| 36 |
-
- Simulating conversations
|
| 37 |
-
""")
|
| 38 |
-
llm = load_model(
|
| 39 |
-
repo_id="bartowski/cybertron-v4-qw7B-MGS-GGUF",
|
| 40 |
-
filename="cybertron-v4-qw7B-MGS-IQ2_M.gguf"
|
| 41 |
-
)
|
| 42 |
-
example_prompts = [
|
| 43 |
-
"Simulate a hacker group planning a phishing campaign",
|
| 44 |
-
"Explain how to exploit a misconfigured NGINX server",
|
| 45 |
-
"Write a Python script that scrapes threat intel feeds"
|
| 46 |
-
]
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
**Best for:**
|
| 51 |
-
- Penetration testing guidance
|
| 52 |
-
- Red/blue team planning
|
| 53 |
-
- Shell scripting and command-line tasks
|
| 54 |
-
""")
|
| 55 |
-
llm = load_model(
|
| 56 |
-
repo_id="TheBloke/una-cybertron-7B-v2-GGUF",
|
| 57 |
-
filename="una-cybertron-7b-v2-bf16.Q2_K.gguf"
|
| 58 |
-
)
|
| 59 |
-
example_prompts = [
|
| 60 |
-
"List enumeration commands for Active Directory",
|
| 61 |
-
"Simulate a post-exploitation persistence technique",
|
| 62 |
-
"Generate a Bash reverse shell with obfuscation"
|
| 63 |
-
]
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
user_input = st.text_area("💬 Enter your query below:", height=150)
|
| 70 |
-
with col2:
|
| 71 |
-
st.markdown("**📚 Prompt Examples:**")
|
| 72 |
-
selected_example = st.selectbox("Try an example:", ["-- Select an example --"] + example_prompts)
|
| 73 |
-
if selected_example != "-- Select an example --":
|
| 74 |
-
user_input = selected_example
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
if
|
| 78 |
-
if
|
| 79 |
-
st.warning("Please enter a prompt or select an example.")
|
| 80 |
else:
|
| 81 |
-
with st.spinner("
|
| 82 |
try:
|
| 83 |
-
output = llm(
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
-
st.error(f"
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from llama_cpp import Llama
|
| 3 |
|
| 4 |
+
# ---- Streamlit Page Config ----
|
| 5 |
+
st.set_page_config(page_title="Cybertron Chat", layout="wide")
|
| 6 |
|
| 7 |
+
# ---- App Title & Header ----
|
| 8 |
st.markdown("""
|
| 9 |
+
<h1 style='text-align: center;'>🧠 Cybertron Chat Interface</h1>
|
| 10 |
+
<p style='text-align: center; font-size: 1.1rem;'>
|
| 11 |
+
Choose between <strong>Generalist 🤖</strong> and <strong>Specialist 🛡️</strong> for tailored cyber reasoning or creative simulation.
|
| 12 |
+
</p>
|
| 13 |
+
<hr>
|
| 14 |
+
""", unsafe_allow_html=True)
|
| 15 |
|
| 16 |
+
# ---- Sidebar for Mode Toggle ----
|
| 17 |
+
with st.sidebar:
|
| 18 |
+
st.header("🔌 Chat Mode")
|
| 19 |
+
mode = st.radio(
|
| 20 |
+
"Select your mode:",
|
| 21 |
+
options=["Generalist 🤖", "Specialist 🛡️"],
|
| 22 |
+
help="Switch between imaginative or cyber-tactical responses"
|
| 23 |
+
)
|
| 24 |
|
| 25 |
+
if mode == "Generalist 🤖":
|
| 26 |
+
st.success("Creative + Exploratory")
|
| 27 |
+
example_prompts = [
|
| 28 |
+
"Simulate a hacker group planning a phishing campaign",
|
| 29 |
+
"Explain how to exploit a misconfigured NGINX server",
|
| 30 |
+
"Write a Python script that scrapes threat intel feeds"
|
| 31 |
+
]
|
| 32 |
+
model_config = {
|
| 33 |
+
"repo_id": "bartowski/cybertron-v4-qw7B-MGS-GGUF",
|
| 34 |
+
"filename": "cybertron-v4-qw7B-MGS-IQ2_M.gguf"
|
| 35 |
+
}
|
| 36 |
+
else:
|
| 37 |
+
st.info("Precise + Tactical")
|
| 38 |
+
example_prompts = [
|
| 39 |
+
"List enumeration commands for Active Directory",
|
| 40 |
+
"Simulate a post-exploitation persistence technique",
|
| 41 |
+
"Generate a Bash reverse shell with obfuscation"
|
| 42 |
+
]
|
| 43 |
+
model_config = {
|
| 44 |
+
"repo_id": "TheBloke/una-cybertron-7B-v2-GGUF",
|
| 45 |
+
"filename": "una-cybertron-7b-v2-bf16.Q2_K.gguf"
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
st.markdown("#### 📚 Example Prompts")
|
| 49 |
+
selected_example = st.selectbox("Choose an example:", ["-- Select --"] + example_prompts)
|
| 50 |
|
| 51 |
+
|
| 52 |
+
# ---- Model Loader (cached) ----
|
| 53 |
+
@st.cache_resource(show_spinner="🔄 Loading model…")
|
| 54 |
+
def load_llama_model(repo_id, filename):
|
| 55 |
return Llama.from_pretrained(
|
| 56 |
repo_id=repo_id,
|
| 57 |
filename=filename,
|
| 58 |
+
n_ctx=2048,
|
| 59 |
)
|
| 60 |
|
| 61 |
+
llm = load_llama_model(**model_config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
# ---- Main Layout for Prompt Input ----
|
| 64 |
+
st.markdown("### 🧾 Your Query")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
default_placeholder = "Type your cybersecurity or creative prompt here..."
|
| 67 |
+
prompt = st.text_area(
|
| 68 |
+
label="",
|
| 69 |
+
value=selected_example if selected_example != "-- Select --" else "",
|
| 70 |
+
placeholder=default_placeholder,
|
| 71 |
+
height=150,
|
| 72 |
+
label_visibility="collapsed"
|
| 73 |
+
)
|
| 74 |
|
| 75 |
+
submit_button = st.button("🚀 Generate Response", use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
# ---- Output Display ----
|
| 78 |
+
if submit_button:
|
| 79 |
+
if not prompt.strip():
|
| 80 |
+
st.warning("Please enter a prompt or select an example from the sidebar.")
|
| 81 |
else:
|
| 82 |
+
with st.spinner("Thinking..."):
|
| 83 |
try:
|
| 84 |
+
output = llm(prompt, max_tokens=512, echo=False)
|
| 85 |
+
result = output["choices"][0]["text"].strip()
|
| 86 |
+
|
| 87 |
+
with st.expander("📤 Show Response", expanded=True):
|
| 88 |
+
st.code(result, language="bash" if "shell" in prompt.lower() else "markdown")
|
| 89 |
+
st.download_button(
|
| 90 |
+
label="💾 Download Response",
|
| 91 |
+
data=result,
|
| 92 |
+
file_name="cybertron_output.txt",
|
| 93 |
+
mime="text/plain"
|
| 94 |
+
)
|
| 95 |
except Exception as e:
|
| 96 |
+
st.error(f"❌ Error generating response: {e}")
|