Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
| 3 |
+
import torch, numpy as np
|
| 4 |
+
from scipy.fft import fft, fftfreq
|
| 5 |
+
|
| 6 |
+
phi = (1 + np.sqrt(5)) / 2
|
| 7 |
+
tok = AutoTokenizer.from_pretrained("antonypamo/ProSavantEngine_Phi9_3")
|
| 8 |
+
model = AutoModelForMaskedLM.from_pretrained("antonypamo/ProSavantEngine_Phi9_3")
|
| 9 |
+
|
| 10 |
+
def phi_score(text):
|
| 11 |
+
inputs = tok(text, return_tensors="pt")
|
| 12 |
+
with torch.no_grad():
|
| 13 |
+
outs = model(**inputs, output_hidden_states=True)
|
| 14 |
+
h = torch.stack(outs.hidden_states).mean(dim=0).squeeze(0).cpu().numpy()
|
| 15 |
+
s = np.abs(fft(h.mean(axis=1)))
|
| 16 |
+
f = fftfreq(len(s), d=1.0)[:len(s)//2]
|
| 17 |
+
a = s[:len(f)]
|
| 18 |
+
w = np.cos(f*np.pi/phi)**2
|
| 19 |
+
sc = np.dot(a,w)/(np.linalg.norm(a)*np.linalg.norm(w))
|
| 20 |
+
return float((sc+1)/2)
|
| 21 |
+
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=phi_score,
|
| 24 |
+
inputs=gr.Textbox(label="Enter text"),
|
| 25 |
+
outputs=gr.Number(label="Φ-weighted coherence (0–1)"),
|
| 26 |
+
title="ProSavantEngine Φ9.3 — Resonance Analyzer"
|
| 27 |
+
)
|
| 28 |
+
demo.launch()
|