Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,125 +1,190 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import json
|
| 3 |
-
import os
|
| 4 |
from defrag_engine import DefragDeepCompute
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
engine = DefragDeepCompute()
|
| 8 |
|
| 9 |
-
# --- THE
|
| 10 |
-
def
|
| 11 |
-
# 1.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
-
"
|
| 18 |
-
"
|
| 19 |
-
"minute": int(time.split(':')[1]),
|
| 20 |
-
"city": city,
|
| 21 |
-
"nation": "US" # Defaulting for prototype
|
| 22 |
}
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
# FIXED: Calling the correct method 'execute_defrag' with dictionary
|
| 26 |
soul_log = engine.execute_defrag(birth_data, user_input)
|
|
|
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
astrology = soul_log.get('astrology', {})
|
| 31 |
-
iching = soul_log.get('iching', {})
|
| 32 |
-
stability = soul_log.get('stability_score', 75)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
sun_sign = astrology.get('sun_sign', 'Unknown')
|
| 38 |
-
hexagram_lines = iching.get('hexagram_lines', [])
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
"""
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
# 5. Return: Visual Data (for JS), Status, Mechanics, Vector
|
| 55 |
-
# We pass the JS update arguments as a list
|
| 56 |
visual_args = [
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
]
|
| 62 |
|
| 63 |
-
return visual_args,
|
| 64 |
|
| 65 |
-
# --- THE
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
# RIGHT COLUMN: VISUALS & OUTPUT
|
| 89 |
-
with gr.Column(scale=1):
|
| 90 |
-
# HTML COMPONENT FOR MANDALA
|
| 91 |
-
# We load the file content directly
|
| 92 |
-
with open("mandala_component.html", "r") as f:
|
| 93 |
-
html_code = f.read()
|
| 94 |
-
|
| 95 |
-
mandala_display = gr.HTML(value=html_code)
|
| 96 |
-
|
| 97 |
-
# JS Bridge to update the canvas
|
| 98 |
-
js_bridge = """
|
| 99 |
-
(args) => {
|
| 100 |
-
if (window.hexa) {
|
| 101 |
-
window.hexa.updateParams(args[0], args[1], args[2], args[3]);
|
| 102 |
-
}
|
| 103 |
-
return args;
|
| 104 |
-
}
|
| 105 |
-
"""
|
| 106 |
-
|
| 107 |
-
# OUTPUT MONITORS
|
| 108 |
-
status_out = gr.Textbox(label="SYSTEM STATUS", interactive=False)
|
| 109 |
-
mech_out = gr.TextArea(label="MECHANICS LOG", interactive=False)
|
| 110 |
-
vector_out = gr.Textbox(label="VECTOR DIRECTIVE", interactive=False)
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
# WIRING
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
)
|
| 121 |
|
| 122 |
-
# Trigger JS
|
| 123 |
visual_data.change(None, [visual_data], None, js=js_bridge)
|
| 124 |
|
| 125 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from defrag_engine import DefragDeepCompute
|
| 3 |
+
import datetime
|
| 4 |
|
| 5 |
+
# --- INITIALIZATION ---
|
| 6 |
engine = DefragDeepCompute()
|
| 7 |
|
| 8 |
+
# --- THE TRANSLATION LAYER (Logic) ---
|
| 9 |
+
def run_alignment(user_input, name="User", dob="1990-01-01", time="12:00", city="Los Angeles"):
|
| 10 |
+
# 1. Background Compute (Deep Engine)
|
| 11 |
+
# Note: In a full production app, these hardcoded values come from the user's saved profile.
|
| 12 |
+
birth_data = {
|
| 13 |
+
"name": name,
|
| 14 |
+
"date": dob,
|
| 15 |
+
"time": time,
|
| 16 |
+
"city": city,
|
| 17 |
+
"country_code": "US"
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
+
# Execute the Core Physics Engine
|
|
|
|
| 21 |
soul_log = engine.execute_defrag(birth_data, user_input)
|
| 22 |
+
vector = soul_log['computed_vector']
|
| 23 |
|
| 24 |
+
# 2. The "Premium" UI Translation
|
| 25 |
+
# We convert raw data (Friction/Elements) into consumer-facing "Context"
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
friction = vector['friction_level']
|
| 28 |
+
p_day = soul_log['hardware']['numerology']['personal_day']
|
| 29 |
+
element = soul_log['weather']['astro']['dominant_element'].title()
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
if friction == "CRITICAL":
|
| 32 |
+
status_header = "⚠️ HIGH INTERFERENCE"
|
| 33 |
+
status_color = "#FF5F00" # Safety Orange
|
| 34 |
+
context_msg = f"We have detected a **Resistance Pattern** in your immediate field. You are navigating a **High-Velocity Cycle (Day {p_day})** that is currently opposing the environmental flow."
|
| 35 |
+
directive = "DIRECTIVE: PAUSE. Do not initiate action. Allow the signal to clear."
|
| 36 |
+
else:
|
| 37 |
+
status_header = "✓ SIGNAL CLEAR"
|
| 38 |
+
status_color = "#00F0FF" # Electric Cyan
|
| 39 |
+
context_msg = f"Your internal rhythm is coherent with the environment. You are currently supported by **{element} Energy**, providing a stable foundation for action."
|
| 40 |
+
directive = "DIRECTIVE: PROCEED WITH INTENT."
|
| 41 |
+
|
| 42 |
+
# 3. Construct the "Insight Card" (Markdown)
|
| 43 |
+
insight_html = f"""
|
| 44 |
+
<div style="background: #111; border: 1px solid #333; border-radius: 16px; padding: 24px; margin-top: 20px; animation: fadeIn 1s ease;">
|
| 45 |
+
<h2 style="color: {status_color}; margin: 0 0 10px 0; font-size: 18px; letter-spacing: 1px; text-transform: uppercase;">{status_header}</h2>
|
| 46 |
+
<p style="color: #CCC; font-size: 15px; line-height: 1.5; margin-bottom: 20px;">{context_msg}</p>
|
| 47 |
+
<div style="border-top: 1px solid #333; padding-top: 15px;">
|
| 48 |
+
<strong style="color: #FFF; font-size: 14px; letter-spacing: 0.5px;">{directive}</strong>
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
"""
|
| 52 |
|
| 53 |
+
# 4. Visual Parameters for the Mandala (passed to JS)
|
|
|
|
|
|
|
|
|
|
| 54 |
visual_args = [
|
| 55 |
+
vector['visual_code'], # Hexagram Rings
|
| 56 |
+
vector['visual_seed'], # Numerology Petals
|
| 57 |
+
vector['visual_element'], # Element Color
|
| 58 |
+
0.3 if friction == "CRITICAL" else 1.0 # Stability Score
|
| 59 |
]
|
| 60 |
|
| 61 |
+
return visual_args, insight_html
|
| 62 |
|
| 63 |
+
# --- THE PREMIUM VISUAL LAYER (CSS) ---
|
| 64 |
+
premium_css = """
|
| 65 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap');
|
| 66 |
+
|
| 67 |
+
body, .gradio-container {
|
| 68 |
+
background-color: #000000 !important;
|
| 69 |
+
color: #F0F0F0 !important;
|
| 70 |
+
font-family: 'Inter', sans-serif !important;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/* Mobile-First App Container */
|
| 74 |
+
.gradio-container {
|
| 75 |
+
max-width: 420px !important;
|
| 76 |
+
margin: 0 auto !important;
|
| 77 |
+
padding: 20px !important;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/* The Monitor (Mandala) */
|
| 81 |
+
#monitor-frame {
|
| 82 |
+
width: 280px;
|
| 83 |
+
height: 280px;
|
| 84 |
+
margin: 20px auto;
|
| 85 |
+
border-radius: 50%;
|
| 86 |
+
border: 1px solid #222;
|
| 87 |
+
box-shadow: 0 0 40px rgba(0, 240, 255, 0.05); /* Subtle Cyan Glow */
|
| 88 |
+
overflow: hidden;
|
| 89 |
+
background: #000;
|
| 90 |
+
transition: all 0.5s ease;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/* Input Field - Stealth Mode */
|
| 94 |
+
.stealth-input textarea {
|
| 95 |
+
background: #111 !important;
|
| 96 |
+
border: 1px solid #222 !important;
|
| 97 |
+
color: #FFF !important;
|
| 98 |
+
font-size: 16px !important;
|
| 99 |
+
padding: 16px !important;
|
| 100 |
+
border-radius: 12px !important;
|
| 101 |
+
outline: none !important;
|
| 102 |
+
box-shadow: none !important;
|
| 103 |
+
}
|
| 104 |
+
.stealth-input textarea::placeholder { color: #555 !important; }
|
| 105 |
+
|
| 106 |
+
/* The Action Button */
|
| 107 |
+
.align-btn {
|
| 108 |
+
background: #FFFFFF !important;
|
| 109 |
+
color: #000000 !important;
|
| 110 |
+
border: none !important;
|
| 111 |
+
border-radius: 30px !important;
|
| 112 |
+
font-weight: 600 !important;
|
| 113 |
+
font-size: 14px !important;
|
| 114 |
+
letter-spacing: 2px !important;
|
| 115 |
+
height: 50px !important;
|
| 116 |
+
margin-top: 15px !important;
|
| 117 |
+
transition: transform 0.2s ease !important;
|
| 118 |
+
}
|
| 119 |
+
.align-btn:hover {
|
| 120 |
+
box-shadow: 0 0 20px rgba(255, 255, 255, 0.3) !important;
|
| 121 |
+
transform: scale(1.02);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/* Animations */
|
| 125 |
+
@keyframes fadeIn {
|
| 126 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 127 |
+
to { opacity: 1; transform: translateY(0); }
|
| 128 |
+
}
|
| 129 |
+
"""
|
| 130 |
+
|
| 131 |
+
# --- THE APPLICATION BLOCKS ---
|
| 132 |
+
with gr.Blocks(theme=gr.themes.Base(), css=premium_css, title="DEFRAG") as demo:
|
| 133 |
|
| 134 |
+
# 1. HIDDEN STATE (Profile Data)
|
| 135 |
+
# In a real app, this is persistent. Here we hardcode for the prototype.
|
| 136 |
+
with gr.Row(visible=False):
|
| 137 |
+
name_in = gr.Textbox(value="User")
|
| 138 |
+
dob_in = gr.Textbox(value="1990-01-01")
|
| 139 |
+
time_in = gr.Textbox(value="12:00")
|
| 140 |
+
city_in = gr.Textbox(value="Los Angeles")
|
| 141 |
+
|
| 142 |
+
# 2. THE INTERFACE
|
| 143 |
+
with gr.Column():
|
| 144 |
+
|
| 145 |
+
# A. THE MONITOR
|
| 146 |
+
# Loads the HexaMandala HTML and frames it
|
| 147 |
+
with open("mandala_component.html", "r") as f:
|
| 148 |
+
html_content = f.read().replace("500px", "100%") # Ensure fit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
+
gr.HTML(f"<div id='monitor-frame'>{html_content}</div>")
|
| 151 |
+
|
| 152 |
+
# B. THE INPUT
|
| 153 |
+
user_input = gr.Textbox(
|
| 154 |
+
placeholder="Type your state...",
|
| 155 |
+
show_label=False,
|
| 156 |
+
lines=2,
|
| 157 |
+
elem_classes="stealth-input"
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
# C. THE TRIGGER
|
| 161 |
+
btn_align = gr.Button("ALIGN", elem_classes="align-btn")
|
| 162 |
+
|
| 163 |
+
# D. THE INSIGHT CARD (Output)
|
| 164 |
+
output_card = gr.HTML(label=None)
|
| 165 |
|
| 166 |
+
# 3. WIRING & DATA BRIDGE
|
| 167 |
+
# Hidden JSON component to pass data to JavaScript
|
| 168 |
+
visual_data = gr.JSON(visible=False)
|
| 169 |
+
|
| 170 |
+
# JavaScript Bridge: Listens for changes in 'visual_data' and updates the canvas
|
| 171 |
+
js_bridge = """
|
| 172 |
+
(args) => {
|
| 173 |
+
if (window.hexa) {
|
| 174 |
+
window.hexa.updateParams(args[0], args[1], args[2], args[3]);
|
| 175 |
+
}
|
| 176 |
+
return args;
|
| 177 |
+
}
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
# Event Listener
|
| 181 |
+
btn_align.click(
|
| 182 |
+
fn=run_alignment,
|
| 183 |
+
inputs=[user_input, name_in, dob_in, time_in, city_in],
|
| 184 |
+
outputs=[visual_data, output_card]
|
| 185 |
)
|
| 186 |
|
| 187 |
+
# Trigger JS when data returns
|
| 188 |
visual_data.change(None, [visual_data], None, js=js_bridge)
|
| 189 |
|
| 190 |
if __name__ == "__main__":
|