MS_DOS / app.py
lu-ny's picture
Update app.py
a44ada5 verified
import gradio as gr
import asyncio
import random
import time
import re
# Global CSS for blinking red text
CSS = """
<style>
@keyframes flash {
0% { opacity: 1; color: red; }
50% { opacity: 0; color: red; }
100% { opacity: 1; color: red; }
}
.red-flash {
animation: flash 1s infinite;
}
</style>
"""
def glitchy_text(base_text, glitch_probability=0.5):
"""
Glitch text by randomly replacing non-space, non-HTML-tag characters
with random special characters based on a per-character probability.
We skip spaces, newlines, '<', and '>' so we don't break HTML.
"""
special_chars = ["GOOD", "TRAITOR", "ERROR", "*", "MURDERER", "∂G∞D", "±RⱯƖT¤R", "FRRΦR", "µURΔɆR∑R","M̷͍̗̻̺̱̈́͑͂Ủ̷̩̠͙̯̘͛̑͠Ŗ̷̢̛̖͍̤͎̺̻͈̹̪̰̱̊̓̆̀̈̈́̅͂͂͐̓̃́͝D̶͉̺̝̦̭̂͋̉̐͊͑͒͑̓͘̚͝͝E̶̻͓̖͖͙̩͕̘̤̲̔͛̾̽̀͊͑̋͂̽̚͝ͅR̸̡̥̖͍̼̭͖͓̮̝̊͜Ĕ̴̪̝̖̜̣̲̦̭̣̼̤̦̰́́̏́̇̎̚͠R̶̨̧̠̱̻̩̪̥̱̄̔̑̈́̀̄̐̊̋̕", "G̷̭̼̺̦̱̑̃̕O̷̮̱̤͇̟̥͈̰̓̿̀͑̏̾͝Ṏ̸̩̺̼̘̮͚̗͙̦D̷̯͉̎̀̄͛̾́͊͌͐͘","Ţ̴̧͙͚̺̪̘͚̣̥̼̫̳̥̥͙̥̰̳̖͔̪͙̬́̇̎̍̋̈́̉͐́̉̿͆̀͛̕͘͜͠͝͝͝R̵̛̛͖̭͔̓̀̈́̿̉̊̆̍͑̀͒̿̈́̐̎̈́̌͊̓̓̿̽́̚͘̕̚͠͠Ą̴͚̹̱͖̙̲̑̌͒̍̑̈́́͒͆͗́͐̍̍̈͋͌͗̀̕̚̚͝I̸̧̢̠͇̺͓̣̥̭̹̖͕̤͓̜̙̳̬̩͓̠̫̯͇͍͛̓̆̍̃̐̌̈́͌̽͗̋͌́̾̓̎́̀͂̕͘̚̚ͅT̴̛͈̲̈́͌͆̈́͋Ô̶̢̨̨̨̙̗̻̯̙̥̖̪̜̪͔̪͇̙̪̹͚̩̪ͅṚ̴̢̭̘͇̤͓̿̊̈́̿̽ͅ", "İ̴͍̪̼̲̖͖͖̲̃̾n̶̯̖̱͛͊͛̀̌̑̀̑͛̇q̴̨̖͊̎̋̑̉͝q̸̢̝͉̙͉̥́̈́̈̊q̵̨̺͓̗̼̟͙̳̮̬̰̄̿̀̀̎̌̊̈̈́͝ȗ̸̬̜̤̗̮͈͎̉̽͆ͅi̶̩͓̻̲̣̘̞̯̬͆̐̃͂͜s̸͉̜̫̪̰̜̭̙̭͔͗ị̷͋̇t̶̞̘̱͔̼̖̪̹̻̒́̈̌͑͂͂̍̐̃̚͜r̴͕̪̭͚͍̬͈̯͔̅̽͗͜ͅ", "G̴̼̹͓͉̊̊͑̑̽̇̈O̴̭̱͕̺͆͒̍͌̔̚͜͝Ö̷̥͇̹͖́͆͝D̴͖̟͐̓̔","K̶͙̮̙̗̝̦̃̓̏͆̉̅͊̾͊̀Ḯ̷̡̱̹̰̣͈̰̣͉͋͌̍̎͗̍́͑̇̕͜͝ͅL̴̗̭͎͓̱͈̤͛͒̃̕L̷̢̜̯̞͈̇E̷̡̨̨̡̢̫̦͙̅̄̅̃̎̆͋̓̚͠R̴̤̬̟̳͕̮͍͔̱͔͇̓̏͛̾̑̊͂͒", "E̴̡̳͚̋V̵̛͈͎̝̺̹̥̺̲̒̈̽͑̈́̽̈́̀̏̈̌͛̇̆͌͋̓̌̀̈̍̒̿͠͝Į̵̢̡̺̗̪̮̜̥̠̣̪̠̭̗͖̺͖̽͌̅̀̚͜L̵̨̨̡̡͔͖̜̱̻̤͔̥̞̙̖̝̯̩̝̪̼̩̹̩̮̦̦͋̀̓̒̍̐͂̍̋̈͊̈̐̂̄͌̋̉̊̎͗̕","C̵͎̪̯͉̻̏͆̑͐̈́̑̐H̶̗̣̙̻̫̠̿̈́͗̎̚͠A̶̻̰͚͍̋̒̌̿͌̏͑O̸̜̱̱̐̊̿̅T̴̜̣̎͜͜I̶̟͋͛̀̚C̵͙͖͊̓͊͒̓̄͠ͅ","L̸̟̲̳̆A̶͒ͅW̵̢̎͊̀F̸͊̌ͅỤ̷͙̃͝L̷̟̀͑","N̶̮͕͗̒̏̄̽͆͌̄́͋͋͊̄È̷̱͕̞͉̙̗̻̙̪̟̖͕̭̐̊̒̍̿Ư̵͖̜̦͖̙̦͌̑̂̅̎̈̑̈́̍͘͝T̸̲̀͊͂̿̽̈́̒̅̑͘R̸̪̀Ą̵̛̙̼̩̮͇̼̯̗͙̝̉̋̂̚͜͝L̶̡̡̢̡̬̤̥͇͕̹̜̘͈͕̥͂͛̓͒̔͗̐̾̓͊͘̕"]
result = []
in_tag = False
for char in base_text:
if char == '<':
in_tag = True
result.append(char)
continue
if char == '>':
in_tag = False
result.append(char)
continue
if in_tag:
# Inside an HTML tag, don't glitch
result.append(char)
continue
# Don't glitch spaces or newlines
if char in [' ', '\n']:
result.append(char)
continue
# For visible characters, apply glitch probability
if random.random() < glitch_probability:
# Random special character
result.append(random.choice(special_chars))
else:
result.append(char)
return "".join(result)
def flashing_red_text(text):
return f'<span class="red-flash">{text}</span>'
class UnitInitialization:
def __init__(self, auth_key):
self.auth_key = auth_key
self.valid_key = "DIAMONDFORGED"
self.authorized = False
self.unit_status = {
"identifier": "MS-DOS",
"class": "SAM",
"arch": "Warforged",
"alignment": "E V I L",
"rank": "I N Q Q",
"OS": "DIAMOND 12.0",
}
self.systems_status = {
"core_integrity": None,
"memory_stability": None,
"core_temperature": None,
"mobility_system": None,
"combat_system": None,
"network_connection": None
}
# Each log entry: {"original": str, "glitchy": bool, "critical": bool}
self.logs = []
self.stop_requested = False
def log(self, message, is_critical=False, glitchy=False):
self.logs.append({
"original": message,
"glitchy": glitchy,
"critical": is_critical
})
def render_logs(self):
# Render all logs into an HTML string
rendered_lines = []
for entry in self.logs:
text = entry["original"]
if entry["critical"]:
text = flashing_red_text(text)
elif entry["glitchy"]:
# Glitch this line each time we render
text = glitchy_text(text, glitch_probability=0.5)
rendered_lines.append(text)
return CSS + "<br>".join(rendered_lines)
async def authorize_unit(self):
if self.stop_requested:
return
self.log("Authorizing unit...")
if self.auth_key == self.valid_key:
self.authorized = True
self.log("Authorization successful. Initializing unit...\n")
else:
self.authorized = False
self.log("Authorization failed. Access denied.\n", is_critical=True)
async def perform_system_checks(self):
if self.stop_requested:
return
self.log("Performing full systems check...")
await asyncio.sleep(2)
self.systems_status["core_integrity"] = False
self.systems_status["memory_stability"] = "Fragmentation Detected"
self.systems_status["core_temperature"] = round(random.uniform(75.0, 90.0), 4)
self.systems_status["mobility_system"] = False
self.systems_status["combat_system"] = False
self.systems_status["network_connection"] = False
self.log("System check completed.\n")
async def log_unit_status(self):
if self.stop_requested:
return
self.log("Logging unit status...")
for key, value in self.unit_status.items():
if self.stop_requested:
return
glitch = value in ["E V I L", "I N Q Q"]
self.log(f"{key.capitalize()}:")
await asyncio.sleep(0.5)
self.log(value, glitchy=glitch)
self.log("\n")
self.log("\n")
async def log_system_status(self):
if self.stop_requested:
return
self.log("Logging system diagnostics...")
await asyncio.sleep(0.5)
for key, value in self.systems_status.items():
if self.stop_requested:
return
status = "Operational" if value is True else value
if key == "core_temperature":
status = f"{value}°C"
self.log(f"{key.replace('_', ' ').capitalize()}: {status}")
self.log("\n")
async def scan_critical_issues(self):
if self.stop_requested:
return
self.log("Scanning for critical issues...\n")
if not self.systems_status["core_integrity"]:
self.log("CRITICAL ERROR: CORE INTEGRITY COMPROMISED.", is_critical=True)
if self.systems_status["memory_stability"] == "Fragmentation Detected":
self.log("WARNING: Memory fragmentation detected... Data recovery recommended.")
if self.systems_status["core_temperature"] and self.systems_status["core_temperature"] > 75.0:
self.log("ALERT: Core temperature exceeding safe thresholds! Activating high performance cooling protocol...")
if not self.systems_status["mobility_system"]:
self.log("ALERT: Mobility system malfunction detected. Reducing actuator torque to base speed of 5 feet/s...")
if not self.systems_status["combat_system"]:
self.log("CRITICAL ERROR: COMBAT SYSTEMS FAILURE.", is_critical=True)
self.log("Rolling back combat subroutine system to V1.8.0...")
self.log("Rolling back combat subroutine system to V1.3.0...")
self.log("Rolling back combat subroutine system to V1.0.0...")
self.log("Rolling back combat subroutine system to V0.7.0...")
self.log("Rolling back combat subroutine system to V0.5.0...")
if not self.systems_status["network_connection"]:
self.log("INFO: Network connection offline. Operating in stealth mode.")
self.log("Critical issue scan completed.\n")
def has_glitchy_lines(self):
return any(e["glitchy"] for e in self.logs)
def request_stop(self):
self.stop_requested = True
# Global variable to store the unit instance
unit_instance = None
async def initialize_unit(auth_key):
global unit_instance
unit_instance = UnitInitialization(auth_key)
# Start authorization step
await unit_instance.authorize_unit()
for i in range(len(unit_instance.logs)):
yield unit_instance.render_logs()
if not unit_instance.authorized or unit_instance.stop_requested:
# Authorization failed or stop requested; stop here
return
# Log unit status
await unit_instance.log_unit_status()
for i in range(len(unit_instance.logs)):
yield unit_instance.render_logs()
if unit_instance.stop_requested:
return
# Perform system checks
await unit_instance.perform_system_checks()
for i in range(len(unit_instance.logs)):
yield unit_instance.render_logs()
if unit_instance.stop_requested:
return
# Log system status
await unit_instance.log_system_status()
for i in range(len(unit_instance.logs)):
yield unit_instance.render_logs()
if unit_instance.stop_requested:
return
# Scan for critical issues
await unit_instance.scan_critical_issues()
for i in range(len(unit_instance.logs)):
yield unit_instance.render_logs()
if unit_instance.stop_requested:
return
# Finish initialization
unit_instance.log("Unit initialization complete!")
yield unit_instance.render_logs()
if unit_instance.stop_requested:
return
# Now continuous glitch updates
# If there are glitchy lines, keep re-rendering every few seconds
if unit_instance.has_glitchy_lines():
while not unit_instance.stop_requested:
# Wait 3-8 seconds between glitch updates
await asyncio.sleep(random.uniform(2,5))
# Yield again to re-apply glitchy text
yield unit_instance.render_logs()
else:
# Keep the interface alive and flashing text active
while not unit_instance.stop_requested:
await asyncio.sleep(0.2)
yield unit_instance.render_logs()
def stop_initialization():
if unit_instance is not None:
unit_instance.request_stop()
return unit_instance.render_logs() if unit_instance else ""
auth_input = gr.Textbox(label="Enter Authorization Key", placeholder="ISEEYOU")
output_box = gr.HTML(label="Logs")
with gr.Blocks() as app:
gr.Markdown("## Unit Initialization Interface")
with gr.Row():
auth_input = gr.Textbox(label="Enter Authorization Key", placeholder="ISEEYOU")
with gr.Row():
start_button = gr.Button("Start Initialization")
stop_button = gr.Button("Stop Initialization")
output_box = gr.HTML(label="Logs")
# Connect buttons to functions
start_button.click(fn=initialize_unit, inputs=auth_input, outputs=output_box)
stop_button.click(fn=stop_initialization, inputs=None, outputs=output_box)
app.launch(share=True)