Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,6 +81,129 @@ def normalize_result(res: Dict[str, Any]):
|
|
| 81 |
# ANALYST COPILOT (LLM)
|
| 82 |
# ---------------------------------------------------------------------
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
# -------------------------
|
| 85 |
# Analyst Copilot
|
| 86 |
# -------------------------
|
|
@@ -129,8 +252,11 @@ def normalize_result(res: Dict[str, Any]):
|
|
| 129 |
outputs=[chatbot._chatbot_state],
|
| 130 |
)
|
| 131 |
|
| 132 |
-
|
| 133 |
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
demo = build_interface()
|
|
|
|
| 81 |
# ANALYST COPILOT (LLM)
|
| 82 |
# ---------------------------------------------------------------------
|
| 83 |
|
| 84 |
+
def respond(
|
| 85 |
+
message,
|
| 86 |
+
history,
|
| 87 |
+
system_prompt,
|
| 88 |
+
model_name,
|
| 89 |
+
hf_token,
|
| 90 |
+
temperature,
|
| 91 |
+
top_p,
|
| 92 |
+
max_tokens,
|
| 93 |
+
):
|
| 94 |
+
"""Streaming response from WhiteRabbit Neo or Cybertron."""
|
| 95 |
+
client = InferenceClient(model=model_name, token=hf_token.token)
|
| 96 |
+
|
| 97 |
+
msgs = [{"role": "system", "content": system_prompt}]
|
| 98 |
+
msgs.extend(history)
|
| 99 |
+
msgs.append({"role": "user", "content": message})
|
| 100 |
+
|
| 101 |
+
buf = ""
|
| 102 |
+
for chunk in client.chat_completion(
|
| 103 |
+
messages=msgs,
|
| 104 |
+
max_tokens=max_tokens,
|
| 105 |
+
temperature=temperature,
|
| 106 |
+
top_p=top_p,
|
| 107 |
+
stream=True,
|
| 108 |
+
):
|
| 109 |
+
delta = chunk.choices[0].delta.content
|
| 110 |
+
if delta:
|
| 111 |
+
buf += delta
|
| 112 |
+
yield buf
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def inject_osint(history, osint_obj):
|
| 116 |
+
"""Inject raw JSON results into the chat context."""
|
| 117 |
+
pretty = json.dumps(osint_obj, indent=2, default=str)
|
| 118 |
+
history.append({
|
| 119 |
+
"role": "system",
|
| 120 |
+
"content": f"### Injected OSINT Result\n```\n{pretty}\n```"
|
| 121 |
+
})
|
| 122 |
+
return history
|
| 123 |
+
|
| 124 |
+
# ---------------------------------------------------------------------
|
| 125 |
+
# OSINT Dashboard Callbacks
|
| 126 |
+
# ---------------------------------------------------------------------
|
| 127 |
+
|
| 128 |
+
def ui_lookup_ip(ip, enrich, mitre):
|
| 129 |
+
raw = call_task("lookup_ip", {"ip": ip, "enrich": enrich, "map_mitre": mitre})
|
| 130 |
+
norm = normalize_result(raw)
|
| 131 |
+
return norm["summary"], norm["markdown"], norm["json"], norm["mitre"], norm["stix"], raw
|
| 132 |
+
|
| 133 |
+
def ui_lookup_domain(domain, enrich, mitre):
|
| 134 |
+
raw = call_task("lookup_domain", {"domain": domain, "enrich": enrich, "map_mitre": mitre})
|
| 135 |
+
norm = normalize_result(raw)
|
| 136 |
+
return norm["summary"], norm["markdown"], norm["json"], norm["mitre"], norm["stix"], raw
|
| 137 |
+
|
| 138 |
+
def ui_lookup_hash(h, ht, enrich, mitre):
|
| 139 |
+
raw = call_task("lookup_hash", {"hash": h, "hash_type": ht, "enrich": enrich, "map_mitre": mitre})
|
| 140 |
+
norm = normalize_result(raw)
|
| 141 |
+
return norm["summary"], norm["markdown"], norm["json"], norm["mitre"], norm["stix"], raw
|
| 142 |
+
|
| 143 |
+
def ui_correlate_iocs(iocs):
|
| 144 |
+
lst = [x.strip() for x in iocs.splitlines() if x.strip()]
|
| 145 |
+
raw = call_task("correlate_iocs", {"iocs": lst})
|
| 146 |
+
norm = normalize_result(raw)
|
| 147 |
+
return norm["summary"], norm["markdown"], norm["json"], norm["mitre"], raw
|
| 148 |
+
|
| 149 |
+
def ui_quickscan(target):
|
| 150 |
+
raw = call_task("quickscan", {"target": target})
|
| 151 |
+
norm = normalize_result(raw)
|
| 152 |
+
return norm["summary"], norm["markdown"], norm["json"], raw
|
| 153 |
+
|
| 154 |
+
# ---------------------------------------------------------------------
|
| 155 |
+
# MCP Bridge
|
| 156 |
+
# ---------------------------------------------------------------------
|
| 157 |
+
|
| 158 |
+
def ui_bridge(tool, args_json):
|
| 159 |
+
try:
|
| 160 |
+
payload = json.loads(args_json)
|
| 161 |
+
except Exception as e:
|
| 162 |
+
return json.dumps({"error": str(e)}, indent=2), "", {}
|
| 163 |
+
raw = call_task(tool, payload)
|
| 164 |
+
norm = normalize_result(raw)
|
| 165 |
+
return norm["json"], norm["markdown"], raw
|
| 166 |
+
|
| 167 |
+
# ---------------------------------------------------------------------
|
| 168 |
+
# BUILD UI
|
| 169 |
+
# ---------------------------------------------------------------------
|
| 170 |
+
|
| 171 |
+
def build_interface():
|
| 172 |
+
with gr.Blocks(title="Parrot OSINT MCP Console") as demo:
|
| 173 |
+
gr.Markdown("# Parrot OSINT MCP Console\nA multi-mode intelligence workstation.")
|
| 174 |
+
|
| 175 |
+
osint_state = gr.State({})
|
| 176 |
+
|
| 177 |
+
# -------------------------
|
| 178 |
+
# OSINT Dashboard
|
| 179 |
+
# -------------------------
|
| 180 |
+
with gr.Tab("OSINT Dashboard"):
|
| 181 |
+
with gr.Tab("IP"):
|
| 182 |
+
ip = gr.Textbox(label="IP Address")
|
| 183 |
+
enrich = gr.Checkbox(value=True, label="Enrich")
|
| 184 |
+
mitre = gr.Checkbox(value=True, label="MITRE Map")
|
| 185 |
+
run = gr.Button("Run IP Lookup")
|
| 186 |
+
|
| 187 |
+
s = gr.Textbox(label="Summary")
|
| 188 |
+
md = gr.Markdown()
|
| 189 |
+
js = gr.Code(language="json")
|
| 190 |
+
mt = gr.Code(language="json")
|
| 191 |
+
st = gr.Code(language="json")
|
| 192 |
+
|
| 193 |
+
run.click(ui_lookup_ip, [ip, enrich, mitre], [s, md, js, mt, st, osint_state])
|
| 194 |
+
|
| 195 |
+
# -------------------------
|
| 196 |
+
# MCP Bridge
|
| 197 |
+
# -------------------------
|
| 198 |
+
with gr.Tab("MCP Bridge"):
|
| 199 |
+
tool = gr.Dropdown(sorted(TASK_REGISTRY.keys()))
|
| 200 |
+
args = gr.Code(language="json")
|
| 201 |
+
btn = gr.Button("Call Tool")
|
| 202 |
+
out_js = gr.Code(language="json")
|
| 203 |
+
out_md = gr.Markdown()
|
| 204 |
+
|
| 205 |
+
btn.click(ui_bridge, [tool, args], [out_js, out_md, osint_state])
|
| 206 |
+
|
| 207 |
# -------------------------
|
| 208 |
# Analyst Copilot
|
| 209 |
# -------------------------
|
|
|
|
| 252 |
outputs=[chatbot._chatbot_state],
|
| 253 |
)
|
| 254 |
|
| 255 |
+
return demo
|
| 256 |
|
| 257 |
+
# ---------------------------------------------------------------------
|
| 258 |
+
# MAIN
|
| 259 |
+
# ---------------------------------------------------------------------
|
| 260 |
|
| 261 |
if __name__ == "__main__":
|
| 262 |
demo = build_interface()
|