Research-Stack/5-Applications/tools-scripts/tsm/tsm_upscaler.py

62 lines
2.7 KiB
Python

# ==============================================================================
# COPYRIGHT NO ONE EVERYWHERE LLC (WYOMING HOLDING COMPANY)
# PROJECT: SOVEREIGN STACK
# This artifact is entirely proprietary and cryptographically proven.
# Open-Source usage requires explicit permission from Brandon Scott Schneider.
# ==============================================================================
import argparse
import os
import torch
from diffusers import StableDiffusionUpscalePipeline
from PIL import Image
def upscale(input_file, output_file, steps=50):
print(f"[TSM] Initializing Quantum Super-Resolution Vector Array...")
# Load the base image
try:
init_image = Image.open(input_file).convert("RGB")
except Exception as e:
print(f"[ERROR] Failed to load {input_file}: {e}")
return
print(f"[TSM] Base Tensor Loaded: {init_image.width}x{init_image.height}")
# Load heavily optimized 4x Upscaler
model_id = "stabilityai/stable-diffusion-x4-upscaler"
print(f"[TSM] Booting pi-MoE Optical Node -> {model_id}")
pipe = StableDiffusionUpscalePipeline.from_pretrained(
model_id,
torch_dtype=torch.float16
)
pipe = pipe.to("cuda")
# Optional: Enable memory efficient attention if xformers is installed
try:
pipe.enable_xformers_memory_efficient_attention()
print("[TSM] Xformers memory efficient attention enabled.")
except Exception:
pass
# The prompt helps guide the upscaler's "hallucination" of new pixels
prompt = "highly detailed, hyper-realistic, pristine, 8k resolution, photorealistic, sharp focus, masterpiece"
print(f"[TSM] Injecting physics heuristics and unfolding super-resolution...")
print(f"[TSM] Factoring {steps} inference iterations. Extrapolating to 4x native resolution.")
upscaled_image = pipe(prompt=prompt, image=init_image, num_inference_steps=steps).images[0]
os.makedirs(os.path.dirname(output_file), exist_ok=True)
upscaled_image.save(output_file)
print(f"[TSM] Image Matrix Re-compiled. Final Resolution: {upscaled_image.width}x{upscaled_image.height}")
print(f"[TSM] Vision Solidified at: {os.path.abspath(output_file)}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="TSM 4x Super-Resolution Upscaler.")
parser.add_argument("--input", type=str, required=True, help="Input image path.")
parser.add_argument("--output", type=str, default="5-Applications/out/mind_eye/logic_signal_substrate_upscaled.png", help="Output image path.")
parser.add_argument("--steps", type=int, default=50, help="Inference steps for diffusion upscaling.")
args = parser.parse_args()
upscale(args.input, args.output, args.steps)