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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import asyncio
|
| 3 |
+
import random
|
| 4 |
+
import time
|
| 5 |
+
import re
|
| 6 |
+
|
| 7 |
+
# Global CSS for blinking red text
|
| 8 |
+
CSS = """
|
| 9 |
+
<style>
|
| 10 |
+
@keyframes flash {
|
| 11 |
+
0% { opacity: 1; color: red; }
|
| 12 |
+
50% { opacity: 0; color: red; }
|
| 13 |
+
100% { opacity: 1; color: red; }
|
| 14 |
+
}
|
| 15 |
+
.red-flash {
|
| 16 |
+
animation: flash 1s infinite;
|
| 17 |
+
}
|
| 18 |
+
</style>
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
def glitchy_text(base_text, glitch_probability=0.5):
|
| 22 |
+
"""
|
| 23 |
+
Glitch text by randomly replacing non-space, non-HTML-tag characters
|
| 24 |
+
with random special characters based on a per-character probability.
|
| 25 |
+
We skip spaces, newlines, '<', and '>' so we don't break HTML.
|
| 26 |
+
"""
|
| 27 |
+
special_chars = ["L","·","Ɔ","W","F","?","Ɇ","Ɐ","¡","Ɩ","¤","±","µ","Ɯ","Φ","Ω","≈","∑","√","∞","≠","Ψ","ζ","Δ","?", "≡","≅", "∂", "∴", "⌘", "G", "O","D", "GOOD", "TRAITOR", "ERROR", "*", "MURDERER"]
|
| 28 |
+
result = []
|
| 29 |
+
in_tag = False
|
| 30 |
+
for char in base_text:
|
| 31 |
+
if char == '<':
|
| 32 |
+
in_tag = True
|
| 33 |
+
result.append(char)
|
| 34 |
+
continue
|
| 35 |
+
if char == '>':
|
| 36 |
+
in_tag = False
|
| 37 |
+
result.append(char)
|
| 38 |
+
continue
|
| 39 |
+
if in_tag:
|
| 40 |
+
# Inside an HTML tag, don't glitch
|
| 41 |
+
result.append(char)
|
| 42 |
+
continue
|
| 43 |
+
|
| 44 |
+
# Don't glitch spaces or newlines
|
| 45 |
+
if char in [' ', '\n']:
|
| 46 |
+
result.append(char)
|
| 47 |
+
continue
|
| 48 |
+
|
| 49 |
+
# For visible characters, apply glitch probability
|
| 50 |
+
if random.random() < glitch_probability:
|
| 51 |
+
# Random special character
|
| 52 |
+
result.append(random.choice(special_chars))
|
| 53 |
+
else:
|
| 54 |
+
result.append(char)
|
| 55 |
+
return "".join(result)
|
| 56 |
+
|
| 57 |
+
def flashing_red_text(text):
|
| 58 |
+
return f'<span class="red-flash">{text}</span>'
|
| 59 |
+
|
| 60 |
+
class UnitInitialization:
|
| 61 |
+
def __init__(self, auth_key):
|
| 62 |
+
self.auth_key = auth_key
|
| 63 |
+
self.valid_key = "DIAMONDFORGED"
|
| 64 |
+
self.authorized = False
|
| 65 |
+
self.unit_status = {
|
| 66 |
+
"identifier": "MS-DOS",
|
| 67 |
+
"class": "SAM",
|
| 68 |
+
"arch": "Warforged",
|
| 69 |
+
"alignment": "LAWFUL EVIL",
|
| 70 |
+
"rank": "****** Inqqquisitor",
|
| 71 |
+
"OS": "DIAMOND 12.0",
|
| 72 |
+
}
|
| 73 |
+
self.systems_status = {
|
| 74 |
+
"core_integrity": None,
|
| 75 |
+
"memory_stability": None,
|
| 76 |
+
"core_temperature": None,
|
| 77 |
+
"mobility_system": None,
|
| 78 |
+
"combat_system": None,
|
| 79 |
+
"network_connection": None
|
| 80 |
+
}
|
| 81 |
+
# Each log entry: {"original": str, "glitchy": bool, "critical": bool}
|
| 82 |
+
self.logs = []
|
| 83 |
+
self.stop_requested = False
|
| 84 |
+
|
| 85 |
+
def log(self, message, is_critical=False, glitchy=False):
|
| 86 |
+
self.logs.append({
|
| 87 |
+
"original": message,
|
| 88 |
+
"glitchy": glitchy,
|
| 89 |
+
"critical": is_critical
|
| 90 |
+
})
|
| 91 |
+
|
| 92 |
+
def render_logs(self):
|
| 93 |
+
# Render all logs into an HTML string
|
| 94 |
+
rendered_lines = []
|
| 95 |
+
for entry in self.logs:
|
| 96 |
+
text = entry["original"]
|
| 97 |
+
if entry["critical"]:
|
| 98 |
+
text = flashing_red_text(text)
|
| 99 |
+
elif entry["glitchy"]:
|
| 100 |
+
# Glitch this line each time we render
|
| 101 |
+
text = glitchy_text(text, glitch_probability=0.5)
|
| 102 |
+
rendered_lines.append(text)
|
| 103 |
+
return CSS + "<br>".join(rendered_lines)
|
| 104 |
+
|
| 105 |
+
async def authorize_unit(self):
|
| 106 |
+
if self.stop_requested:
|
| 107 |
+
return
|
| 108 |
+
self.log("Authorizing unit...")
|
| 109 |
+
if self.auth_key == self.valid_key:
|
| 110 |
+
self.authorized = True
|
| 111 |
+
self.log("Authorization successful. Initializing unit...\n")
|
| 112 |
+
else:
|
| 113 |
+
self.authorized = False
|
| 114 |
+
self.log("Authorization failed. Access denied.\n", is_critical=True)
|
| 115 |
+
|
| 116 |
+
async def perform_system_checks(self):
|
| 117 |
+
if self.stop_requested:
|
| 118 |
+
return
|
| 119 |
+
self.log("Performing full systems check...")
|
| 120 |
+
await asyncio.sleep(2)
|
| 121 |
+
self.systems_status["core_integrity"] = False
|
| 122 |
+
self.systems_status["memory_stability"] = "Fragmentation Detected"
|
| 123 |
+
self.systems_status["core_temperature"] = round(random.uniform(75.0, 90.0), 4)
|
| 124 |
+
self.systems_status["mobility_system"] = False
|
| 125 |
+
self.systems_status["combat_system"] = False
|
| 126 |
+
self.systems_status["network_connection"] = False
|
| 127 |
+
self.log("System check completed.\n")
|
| 128 |
+
|
| 129 |
+
async def log_unit_status(self):
|
| 130 |
+
if self.stop_requested:
|
| 131 |
+
return
|
| 132 |
+
self.log("Logging unit status...")
|
| 133 |
+
for key, value in self.unit_status.items():
|
| 134 |
+
if self.stop_requested:
|
| 135 |
+
return
|
| 136 |
+
glitch = value in ["LAWFUL EVIL", "****** Inqqquisitor"]
|
| 137 |
+
self.log(f"{key.capitalize()}:")
|
| 138 |
+
await asyncio.sleep(0.5)
|
| 139 |
+
self.log(value, glitchy=glitch)
|
| 140 |
+
self.log("\n")
|
| 141 |
+
self.log("\n")
|
| 142 |
+
|
| 143 |
+
async def log_system_status(self):
|
| 144 |
+
if self.stop_requested:
|
| 145 |
+
return
|
| 146 |
+
self.log("Logging system diagnostics...")
|
| 147 |
+
await asyncio.sleep(0.5)
|
| 148 |
+
for key, value in self.systems_status.items():
|
| 149 |
+
if self.stop_requested:
|
| 150 |
+
return
|
| 151 |
+
status = "Operational" if value is True else value
|
| 152 |
+
if key == "core_temperature":
|
| 153 |
+
status = f"{value}°C"
|
| 154 |
+
self.log(f"{key.replace('_', ' ').capitalize()}: {status}")
|
| 155 |
+
self.log("\n")
|
| 156 |
+
|
| 157 |
+
async def scan_critical_issues(self):
|
| 158 |
+
if self.stop_requested:
|
| 159 |
+
return
|
| 160 |
+
self.log("Scanning for critical issues...\n")
|
| 161 |
+
if not self.systems_status["core_integrity"]:
|
| 162 |
+
self.log("CRITICAL ERROR: CORE INTEGRITY COMPROMISED.", is_critical=True)
|
| 163 |
+
if self.systems_status["memory_stability"] == "Fragmentation Detected":
|
| 164 |
+
self.log("WARNING: Memory fragmentation detected... Data recovery recommended.")
|
| 165 |
+
if self.systems_status["core_temperature"] and self.systems_status["core_temperature"] > 75.0:
|
| 166 |
+
self.log("ALERT: Core temperature exceeding safe thresholds! Activating high performance cooling protocol...")
|
| 167 |
+
if not self.systems_status["mobility_system"]:
|
| 168 |
+
self.log("ALERT: Mobility system malfunction detected. Reducing actuator torque to base speed of 5 feet/s...")
|
| 169 |
+
if not self.systems_status["combat_system"]:
|
| 170 |
+
self.log("CRITICAL ERROR: COMBAT SYSTEMS FAILURE.", is_critical=True)
|
| 171 |
+
self.log("Rolling back combat subroutine system to V1.8.0...")
|
| 172 |
+
self.log("Rolling back combat subroutine system to V1.3.0...")
|
| 173 |
+
self.log("Rolling back combat subroutine system to V1.0.0...")
|
| 174 |
+
self.log("Rolling back combat subroutine system to V0.7.0...")
|
| 175 |
+
self.log("Rolling back combat subroutine system to V0.5.0...")
|
| 176 |
+
if not self.systems_status["network_connection"]:
|
| 177 |
+
self.log("INFO: Network connection offline. Operating in stealth mode.")
|
| 178 |
+
self.log("Critical issue scan completed.\n")
|
| 179 |
+
|
| 180 |
+
def has_glitchy_lines(self):
|
| 181 |
+
return any(e["glitchy"] for e in self.logs)
|
| 182 |
+
|
| 183 |
+
def request_stop(self):
|
| 184 |
+
self.stop_requested = True
|
| 185 |
+
|
| 186 |
+
# Global variable to store the unit instance
|
| 187 |
+
unit_instance = None
|
| 188 |
+
|
| 189 |
+
async def initialize_unit(auth_key):
|
| 190 |
+
global unit_instance
|
| 191 |
+
unit_instance = UnitInitialization(auth_key)
|
| 192 |
+
|
| 193 |
+
# Start authorization step
|
| 194 |
+
await unit_instance.authorize_unit()
|
| 195 |
+
for i in range(len(unit_instance.logs)):
|
| 196 |
+
yield unit_instance.render_logs()
|
| 197 |
+
if not unit_instance.authorized or unit_instance.stop_requested:
|
| 198 |
+
# Authorization failed or stop requested; stop here
|
| 199 |
+
return
|
| 200 |
+
|
| 201 |
+
# Log unit status
|
| 202 |
+
await unit_instance.log_unit_status()
|
| 203 |
+
for i in range(len(unit_instance.logs)):
|
| 204 |
+
yield unit_instance.render_logs()
|
| 205 |
+
if unit_instance.stop_requested:
|
| 206 |
+
return
|
| 207 |
+
|
| 208 |
+
# Perform system checks
|
| 209 |
+
await unit_instance.perform_system_checks()
|
| 210 |
+
for i in range(len(unit_instance.logs)):
|
| 211 |
+
yield unit_instance.render_logs()
|
| 212 |
+
if unit_instance.stop_requested:
|
| 213 |
+
return
|
| 214 |
+
|
| 215 |
+
# Log system status
|
| 216 |
+
await unit_instance.log_system_status()
|
| 217 |
+
for i in range(len(unit_instance.logs)):
|
| 218 |
+
yield unit_instance.render_logs()
|
| 219 |
+
if unit_instance.stop_requested:
|
| 220 |
+
return
|
| 221 |
+
|
| 222 |
+
# Scan for critical issues
|
| 223 |
+
await unit_instance.scan_critical_issues()
|
| 224 |
+
for i in range(len(unit_instance.logs)):
|
| 225 |
+
yield unit_instance.render_logs()
|
| 226 |
+
if unit_instance.stop_requested:
|
| 227 |
+
return
|
| 228 |
+
|
| 229 |
+
# Finish initialization
|
| 230 |
+
unit_instance.log("Unit initialization complete!")
|
| 231 |
+
yield unit_instance.render_logs()
|
| 232 |
+
if unit_instance.stop_requested:
|
| 233 |
+
return
|
| 234 |
+
|
| 235 |
+
# Now continuous glitch updates
|
| 236 |
+
# If there are glitchy lines, keep re-rendering every few seconds
|
| 237 |
+
if unit_instance.has_glitchy_lines():
|
| 238 |
+
while not unit_instance.stop_requested:
|
| 239 |
+
# Wait 3-8 seconds between glitch updates
|
| 240 |
+
await asyncio.sleep(random.uniform(2,5))
|
| 241 |
+
# Yield again to re-apply glitchy text
|
| 242 |
+
yield unit_instance.render_logs()
|
| 243 |
+
else:
|
| 244 |
+
# Keep the interface alive and flashing text active
|
| 245 |
+
while not unit_instance.stop_requested:
|
| 246 |
+
await asyncio.sleep(0.2)
|
| 247 |
+
yield unit_instance.render_logs()
|
| 248 |
+
|
| 249 |
+
def stop_initialization():
|
| 250 |
+
if unit_instance is not None:
|
| 251 |
+
unit_instance.request_stop()
|
| 252 |
+
return unit_instance.render_logs() if unit_instance else ""
|
| 253 |
+
|
| 254 |
+
auth_input = gr.Textbox(label="Enter Authorization Key", placeholder="ISEEYOU")
|
| 255 |
+
output_box = gr.HTML(label="Logs")
|
| 256 |
+
|
| 257 |
+
with gr.Blocks() as app:
|
| 258 |
+
gr.Markdown("## Unit Initialization Interface")
|
| 259 |
+
with gr.Row():
|
| 260 |
+
auth_input = gr.Textbox(label="Enter Authorization Key", placeholder="ISEEYOU")
|
| 261 |
+
with gr.Row():
|
| 262 |
+
start_button = gr.Button("Start Initialization")
|
| 263 |
+
stop_button = gr.Button("Stop Initialization")
|
| 264 |
+
output_box = gr.HTML(label="Logs")
|
| 265 |
+
|
| 266 |
+
# Connect buttons to functions
|
| 267 |
+
start_button.click(fn=initialize_unit, inputs=auth_input, outputs=output_box)
|
| 268 |
+
stop_button.click(fn=stop_initialization, inputs=None, outputs=output_box)
|
| 269 |
+
|
| 270 |
+
app.launch(share=True)
|