Update app.py
Browse files
app.py
CHANGED
|
@@ -1,81 +1,109 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# -----------------------------
|
| 6 |
-
#
|
| 7 |
# -----------------------------
|
| 8 |
-
def
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
D_render = grad_phi / (1 + tau_eff)
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
if E0 < 0.001:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
elif E0 < 0.1:
|
| 29 |
-
risk = "🔥 Pre-Seismic"
|
| 30 |
-
color = "orange"
|
| 31 |
else:
|
| 32 |
-
|
| 33 |
-
color = "red"
|
| 34 |
-
|
| 35 |
-
# Generate heatmap
|
| 36 |
-
size = 50
|
| 37 |
-
heatmap = np.array([[D_render*100 + i*3 + j*2 for i in range(size)] for j in range(size)])
|
| 38 |
-
|
| 39 |
-
fig, ax = plt.subplots(figsize=(4,4))
|
| 40 |
-
cax = ax.imshow(heatmap, cmap="plasma")
|
| 41 |
-
ax.set_title("Collapse Render Heatmap")
|
| 42 |
-
ax.axis("off")
|
| 43 |
-
fig.colorbar(cax, ax=ax, fraction=0.046, pad=0.04)
|
| 44 |
-
|
| 45 |
-
return D_render, E0, risk, fig
|
| 46 |
|
| 47 |
# -----------------------------
|
| 48 |
-
#
|
| 49 |
# -----------------------------
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
with gr.Row():
|
| 64 |
-
grad_slider = gr.Slider(label="Field Gradient ∇Φ", minimum=0, maximum=2, step=0.01, value=0.5)
|
| 65 |
-
dt_slider = gr.Slider(label="Time Step Δt", minimum=0.01, maximum=1, step=0.01, value=0.1)
|
| 66 |
|
| 67 |
with gr.Row():
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
dt_slider.change(compute_rft, inputs=[phi_slider, tau_slider, grad_slider, dt_slider], outputs=[d_render_out, e0_out, risk_out, heatmap_out])
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
demo.launch()
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
+
import urllib.parse
|
| 6 |
+
from datetime import datetime
|
| 7 |
|
| 8 |
# -----------------------------
|
| 9 |
+
# 1️⃣ RFT Equation0 Computation
|
| 10 |
# -----------------------------
|
| 11 |
+
def compute_E0(phi, tau_eff, grad_phi, dT, gvu):
|
| 12 |
+
"""
|
| 13 |
+
Computes Equation0
|
| 14 |
+
"""
|
| 15 |
D_render = grad_phi / (1 + tau_eff)
|
| 16 |
+
E0 = (D_render / dT) * (1 / gvu)
|
| 17 |
+
return round(D_render, 5), round(E0, 6)
|
| 18 |
+
|
| 19 |
+
# -----------------------------
|
| 20 |
+
# 2️⃣ Heatmap Generation
|
| 21 |
+
# -----------------------------
|
| 22 |
+
def generate_heatmap(E0, phi):
|
| 23 |
+
"""
|
| 24 |
+
Generates a simple heatmap image from E0 values
|
| 25 |
+
"""
|
| 26 |
+
data = np.outer(phi, phi) * E0 # simple demo, can adjust to real field
|
| 27 |
+
plt.figure(figsize=(5,5))
|
| 28 |
+
plt.imshow(data, cmap='hot', interpolation='nearest')
|
| 29 |
+
plt.colorbar(label="E0 intensity")
|
| 30 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 31 |
+
filename = f"heatmap_{timestamp}.png"
|
| 32 |
+
plt.savefig(filename, bbox_inches='tight')
|
| 33 |
+
plt.close()
|
| 34 |
+
return filename
|
| 35 |
+
|
| 36 |
+
# -----------------------------
|
| 37 |
+
# 3️⃣ Viral Twitter/X Link
|
| 38 |
+
# -----------------------------
|
| 39 |
+
def twitter_share_link(caption, image_url=None):
|
| 40 |
+
"""
|
| 41 |
+
Returns a clickable Twitter/X intent URL
|
| 42 |
+
"""
|
| 43 |
+
base_url = "https://twitter.com/intent/tweet?"
|
| 44 |
+
params = {"text": caption}
|
| 45 |
+
if image_url:
|
| 46 |
+
params["url"] = image_url
|
| 47 |
+
query_string = urllib.parse.urlencode(params)
|
| 48 |
+
return f"<a href='{base_url}{query_string}' target='_blank'>Click to Tweet 📢</a>"
|
| 49 |
+
|
| 50 |
+
def generate_caption(E0, risk_level):
|
| 51 |
+
"""
|
| 52 |
+
Generates a viral-ready caption
|
| 53 |
+
"""
|
| 54 |
+
return f"RFT Prediction Alert 🚨\nE0={E0}, Risk={risk_level}\nCheck full RFT analysis! #RFTsystems #Equation0"
|
| 55 |
+
|
| 56 |
+
# -----------------------------
|
| 57 |
+
# 4️⃣ Risk Assessment
|
| 58 |
+
# -----------------------------
|
| 59 |
+
def assess_risk(E0):
|
| 60 |
if E0 < 0.001:
|
| 61 |
+
return "Stable ✅"
|
| 62 |
+
elif 0.001 <= E0 < 0.01:
|
| 63 |
+
return "Mild Stress ⚠️"
|
| 64 |
+
elif 0.01 <= E0 < 0.1:
|
| 65 |
+
return "Pre-Seismic ⚠️🚨"
|
|
|
|
|
|
|
|
|
|
| 66 |
else:
|
| 67 |
+
return "Imminent Collapse ⚡🚨"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# -----------------------------
|
| 70 |
+
# 5️⃣ Full Pipeline
|
| 71 |
# -----------------------------
|
| 72 |
+
def full_pipeline(phi, tau_eff, grad_phi, dT, gvu):
|
| 73 |
+
D_render, E0 = compute_E0(phi, tau_eff, grad_phi, dT, gvu)
|
| 74 |
+
risk = assess_risk(E0)
|
| 75 |
+
heatmap_file = generate_heatmap(E0, np.linspace(0, phi, 10))
|
| 76 |
+
caption = generate_caption(E0, risk)
|
| 77 |
+
tweet_link = twitter_share_link(caption, image_url=None) # Optional: host heatmap online to attach
|
| 78 |
+
return D_render, E0, risk, heatmap_file, tweet_link
|
| 79 |
+
|
| 80 |
+
# -----------------------------
|
| 81 |
+
# 6️⃣ Gradio Interface
|
| 82 |
+
# -----------------------------
|
| 83 |
+
with gr.Blocks() as demo:
|
| 84 |
+
gr.Markdown("# ⚡ RFT Equation0 Prediction System")
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
+
phi_input = gr.Number(label="Φ (Awareness Field)", value=0.5)
|
| 88 |
+
tau_input = gr.Number(label="τ_eff (Collapse Torque)", value=1.72)
|
| 89 |
+
grad_phi_input = gr.Number(label="∇Φ (Field Gradient)", value=0.88)
|
| 90 |
+
dT_input = gr.Number(label="∇Tₚ (Temporal Pressure)", value=2.61)
|
| 91 |
+
gvu_input = gr.Number(label="GVU (Grinstead Voyager Unit)", value=242.718)
|
| 92 |
|
| 93 |
+
compute_btn = gr.Button("Compute Prediction ⚡")
|
| 94 |
|
| 95 |
+
with gr.Row():
|
| 96 |
+
D_render_out = gr.Textbox(label="D_render")
|
| 97 |
+
E0_out = gr.Textbox(label="E0")
|
| 98 |
+
risk_out = gr.Textbox(label="Risk Level")
|
|
|
|
| 99 |
|
| 100 |
+
heatmap_out = gr.Image(label="Heatmap")
|
| 101 |
+
tweet_link_out = gr.HTML(label="Share to Twitter/X")
|
| 102 |
+
|
| 103 |
+
compute_btn.click(
|
| 104 |
+
fn=full_pipeline,
|
| 105 |
+
inputs=[phi_input, tau_input, grad_phi_input, dT_input, gvu_input],
|
| 106 |
+
outputs=[D_render_out, E0_out, risk_out, heatmap_out, tweet_link_out]
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
demo.launch()
|