| import os |
| import gradio as gr |
| from huggingface_hub import InferenceClient |
| from duckduckgo_search import DDGS |
|
|
| |
| MODEL_ID = "Qwen/Qwen2.5-Coder-32B-Instruct" |
| IMAGE_ID = "black-forest-labs/FLUX.1-schnell" |
|
|
| system_halted = False |
|
|
| def toggle_halt(state): |
| global system_halted |
| system_halted = state |
| return "### // STATUS: EMERGENCY HALT //" if state else "### // STATUS: OPERATIONAL //" |
|
|
| def sentinel_scan(query): |
| if system_halted: return "[HALTED]" |
| try: |
| results = DDGS().text(query, max_results=3) |
| return "\n".join([f"- {r['title']}: {r['body']}" for r in results]) |
| except: return "[SENTINEL_OFFLINE]" |
|
|
| def apex_1_logic(message, history, protocol, use_web, use_img): |
| if system_halted: |
| yield "CRITICAL: SYSTEM HALTED BY COMMANDER." |
| return |
|
|
| client = InferenceClient() |
|
|
| if use_img: |
| yield "SYSTEM: GENERATING VISUAL DATA..." |
| img = client.text_to_image(message, model=IMAGE_ID) |
| yield img |
| return |
|
|
| context = sentinel_scan(message) if use_web else "Local Intel Only." |
| prompts = { |
| "WAR_ROOM": "ROLE: Strategic Commander. TONE: Ruthless. GOAL: Global Supremacy.", |
| "WINGMAN": "ROLE: Social Architect. TONE: Charismatic. GOAL: Social Dominance." |
| } |
|
|
| system_instr = f"{prompts[protocol]} | INTEL: {context}" |
| |
| partial = "" |
| messages = [{"role": "system", "content": system_instr}] |
| for h in history: |
| messages.append({"role": "user", "content": h[0]}) |
| messages.append({"role": "assistant", "content": h[1]}) |
| messages.append({"role": "user", "content": message}) |
|
|
| for chunk in client.chat_completion(model=MODEL_ID, messages=messages, max_tokens=2048, stream=True): |
| if chunk.choices[0].delta.content: |
| partial += chunk.choices[0].delta.content |
| yield partial |
|
|
| |
| with gr.Blocks(theme=gr.themes.Monochrome(), css="body {background: #050505; color: #00ffcc;}") as demo: |
| status = gr.Markdown("### // STATUS: OPERATIONAL //") |
| with gr.Row(): |
| protocol = gr.Dropdown(["WAR_ROOM", "WINGMAN"], value="WAR_ROOM", label="PROTOCOL") |
| halt = gr.Checkbox(label="KILL SWITCH", value=False) |
| web = gr.Checkbox(label="SENTINEL_SCAN", value=True) |
| img = gr.Checkbox(label="RENDER_IMAGE", value=False) |
|
|
| chat = gr.Chatbot(height=550, label="APEX-1 LINK") |
| msg = gr.Textbox(placeholder="COMMAND...", label="INPUT") |
|
|
| halt.change(toggle_halt, [halt], [status]) |
| msg.submit(apex_1_logic, [msg, chat, protocol, web, img], [chat]) |
|
|
| if __name__ == "__main__": |
| demo.launch() |