MysticOS / app.py
Jofax's picture
Update app.py
c667fe6 verified
import gradio as gr
import cv2
import numpy as np
import torch
from transformers import pipeline
# --- THE ENGINE: QWEN 2.5 (Open Access / Elite Performance) ---
# This model does NOT require a token or Meta approval.
oracle_pipe = pipeline(
"text-generation",
model="Qwen/Qwen2.5-1.5B-Instruct",
device="cpu",
torch_dtype=torch.float32
)
# --- THE BIOMETRIC HEART ---
def analyze_vital_resonance(frame):
if frame is None: return 0
# Process center of frame for pulse-color variance
h, w, _ = frame.shape
roi = frame[int(h*0.3):int(h*0.6), int(w*0.3):int(w*0.7)]
green_channel = roi[:, :, 1]
vibration_val = np.mean(green_channel)
return int(65 + (vibration_val % 35))
# --- THE ELITE UI STYLE (Neon Obsidian Glass) ---
mystic_css = """
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&display=swap');
.gradio-container {
background: radial-gradient(circle at center, #110922 0%, #020205 100%) !important;
font-family: 'Cinzel', serif !important;
}
.glass-panel {
background: rgba(255, 255, 255, 0.03) !important;
backdrop-filter: blur(15px) !important;
border: 1px solid rgba(212, 175, 55, 0.2) !important;
border-radius: 25px !important;
padding: 20px !important;
}
.oracle-glow {
color: #d4af37 !important;
text-shadow: 0 0 15px rgba(212, 175, 55, 0.8);
font-size: 1.3rem !important;
}
.transmute-btn {
background: linear-gradient(135deg, #7b2ff7 0%, #d4af37 100%) !important;
color: white !important;
font-weight: bold !important;
border: none !important;
}
"""
def transmute_reality(name, sigil, webcam):
vibe = analyze_vital_resonance(webcam)
# System Instruction for the Mystic Persona
system_msg = (
f"You are the Aether Oracle. The initiate's name is {name}. "
f"Their biometric frequency is {vibe}Hz. "
"Speak in profound, futuristic, and mystic riddles. "
"Acknowledge their hand-drawn Sigil as a map to their future."
)
messages = [
{"role": "system", "content": system_msg},
{"role": "user", "content": "I have aligned my biometrics and drawn my sigil. What is my decree?"}
]
# Generate response
output = oracle_pipe(messages, max_new_tokens=200, temperature=0.8)
decree = output[0]['generated_text'][-1]['content']
# Visual Pulse Output
vibe_html = f"""
<div style='text-align: center; border: 2px solid #7b2ff7; border-radius: 15px; padding: 10px; background: rgba(123,47,247,0.1);'>
<h1 style='color: #7b2ff7; margin: 0;'>{vibe}Hz</h1>
<p style='color: #d4af37; margin: 0; font-size: 0.7rem;'>RESONANCE SYNCED</p>
</div>
"""
return decree, vibe_html
# --- THE ARCHITECTURE ---
with gr.Blocks(css=mystic_css) as demo:
gr.Markdown("<h1 style='text-align: center; color: #d4af37;'>✨ AETHER OS: THE INITIATION</h1>")
with gr.Row(elem_classes="glass-panel"):
with gr.Column(scale=1):
name_box = gr.Textbox(label="Initiate Identity", placeholder="Enter name...")
sigil_pad = gr.Sketchpad(label="Sigil of Intent", type="numpy")
camera_feed = gr.Image(label="Biometric Lens", sources="webcam")
launch_btn = gr.Button("🔮 TRANSMUTE SOUL", elem_classes="transmute-btn")
with gr.Column(scale=1):
vibe_status = gr.HTML("<p style='text-align: center;'>Awaiting Frequency...</p>")
oracle_output = gr.Markdown(elem_classes="oracle-glow")
launch_btn.click(
fn=transmute_reality,
inputs=[name_box, sigil_pad, camera_feed],
outputs=[oracle_output, vibe_status]
)
demo.launch()