File size: 985 Bytes
f4caf8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
from transformers import AutoTokenizer, AutoModelForMaskedLM
import torch, numpy as np
from scipy.fft import fft, fftfreq

phi = (1 + np.sqrt(5)) / 2
tok = AutoTokenizer.from_pretrained("antonypamo/ProSavantEngine_Phi9_3")
model = AutoModelForMaskedLM.from_pretrained("antonypamo/ProSavantEngine_Phi9_3")

def phi_score(text):
    inputs = tok(text, return_tensors="pt")
    with torch.no_grad():
        outs = model(**inputs, output_hidden_states=True)
    h = torch.stack(outs.hidden_states).mean(dim=0).squeeze(0).cpu().numpy()
    s = np.abs(fft(h.mean(axis=1)))
    f = fftfreq(len(s), d=1.0)[:len(s)//2]
    a = s[:len(f)]
    w = np.cos(f*np.pi/phi)**2
    sc = np.dot(a,w)/(np.linalg.norm(a)*np.linalg.norm(w))
    return float((sc+1)/2)

demo = gr.Interface(
    fn=phi_score,
    inputs=gr.Textbox(label="Enter text"),
    outputs=gr.Number(label="Φ-weighted coherence (0–1)"),
    title="ProSavantEngine Φ9.3 — Resonance Analyzer"
)
demo.launch()