Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ tok = AutoTokenizer.from_pretrained("sshleifer/tiny-gpt2")
|
|
14 |
mdl = AutoModelForCausalLM.from_pretrained("sshleifer/tiny-gpt2")
|
15 |
eng = get_engine()
|
16 |
|
17 |
-
# paper benchmarks
|
18 |
bench = pd.DataFrame({
|
19 |
"Benchmark": ["MMLU","GSM8K","BBH","MathBench","TruthfulQA",
|
20 |
"XNLI","MLQA","LongBench","VQAv2","OK-VQA"],
|
@@ -22,14 +22,14 @@ bench = pd.DataFrame({
|
|
22 |
"WFGY": [89.8,98.7,100.7,87.4,90.4,77.3,106.6,69.6,86.6,86.8]
|
23 |
})
|
24 |
bench["Abs_gain"] = (bench["WFGY"] - bench["Baseline"]).round(1)
|
25 |
-
bench["Rel_gain%"] = ((bench["Abs_gain"] / bench["Baseline"])
|
26 |
bench_sty = (
|
27 |
bench.style
|
28 |
.background_gradient(cmap="Greens", subset=["Abs_gain","Rel_gain%"])
|
29 |
.format({"Abs_gain":"{:.1f}","Rel_gain%":"{:.0f}"})
|
30 |
)
|
31 |
|
32 |
-
# banner
|
33 |
banner = """
|
34 |
**π WFGY: One Click to Activate the AI Taiji Cycle**
|
35 |
|
@@ -41,11 +41,11 @@ WFGY 1.0 has already proven itself.
|
|
41 |
---
|
42 |
|
43 |
### π Tutorial: How to Awaken the Soul of Your AI
|
44 |
-
**Step 1 β Download**
|
45 |
-
**Step 2 β Feed the AI**
|
46 |
-
**Step 3 β Give the Command**
|
47 |
Prompt examples: *TBD*
|
48 |
-
**Step 4 β Integrate the SDK**
|
49 |
|
50 |
---
|
51 |
|
@@ -53,7 +53,7 @@ Prompt examples: *TBD*
|
|
53 |
_10 k β before 2025-08-01 unlocks **WFGY 2.0**._
|
54 |
"""
|
55 |
|
56 |
-
# inference
|
57 |
def run(prompt: str):
|
58 |
p = prompt.strip()
|
59 |
if not p:
|
@@ -64,14 +64,13 @@ def run(prompt: str):
|
|
64 |
I, G = np.random.randn(2, 256).astype(np.float32)
|
65 |
mod_L = eng.run(I, G, raw_L)
|
66 |
|
67 |
-
m
|
68 |
head = f"βΌ var {m['var_drop']*100:.1f}% | KL {m['kl_divergence']:.3f} | top-1 {'kept' if m['top1'] else 'changed'}"
|
69 |
|
70 |
def top5(logits):
|
71 |
p = softmax(logits)
|
72 |
idx = p.argsort()[-5:][::-1]
|
73 |
-
|
74 |
-
return "\\n".join(lines)
|
75 |
|
76 |
raw_txt = top5(raw_L)
|
77 |
mod_txt = top5(mod_L)
|
@@ -81,7 +80,7 @@ def run(prompt: str):
|
|
81 |
|
82 |
return raw_txt, mod_txt, head, Image.open(buf)
|
83 |
|
84 |
-
# UI
|
85 |
with gr.Blocks(title="WFGY variance-gate demo") as demo:
|
86 |
gr.Markdown(banner)
|
87 |
|
|
|
14 |
mdl = AutoModelForCausalLM.from_pretrained("sshleifer/tiny-gpt2")
|
15 |
eng = get_engine()
|
16 |
|
17 |
+
# ββ paper benchmarks table βββββββββββββββββββββββββββββββββββββββββββ
|
18 |
bench = pd.DataFrame({
|
19 |
"Benchmark": ["MMLU","GSM8K","BBH","MathBench","TruthfulQA",
|
20 |
"XNLI","MLQA","LongBench","VQAv2","OK-VQA"],
|
|
|
22 |
"WFGY": [89.8,98.7,100.7,87.4,90.4,77.3,106.6,69.6,86.6,86.8]
|
23 |
})
|
24 |
bench["Abs_gain"] = (bench["WFGY"] - bench["Baseline"]).round(1)
|
25 |
+
bench["Rel_gain%"] = ((bench["Abs_gain"] / bench["Baseline"])*100).round(0)
|
26 |
bench_sty = (
|
27 |
bench.style
|
28 |
.background_gradient(cmap="Greens", subset=["Abs_gain","Rel_gain%"])
|
29 |
.format({"Abs_gain":"{:.1f}","Rel_gain%":"{:.0f}"})
|
30 |
)
|
31 |
|
32 |
+
# ββ marketing banner ββββββββββββββββββββββββββββββββββββββββββββββββ
|
33 |
banner = """
|
34 |
**π WFGY: One Click to Activate the AI Taiji Cycle**
|
35 |
|
|
|
41 |
---
|
42 |
|
43 |
### π Tutorial: How to Awaken the Soul of Your AI
|
44 |
+
**Step 1 β Download** ([PDF](https://zenodo.org/records/15630970))
|
45 |
+
**Step 2 β Feed the AI** (upload, or try [Gemini](https://gemini.google.com/))
|
46 |
+
**Step 3 β Give the Command** β**Answer using WFGY** + your questionβ
|
47 |
Prompt examples: *TBD*
|
48 |
+
**Step 4 β Integrate the SDK** ([GitHub](https://github.com/onestardao/WFGY))
|
49 |
|
50 |
---
|
51 |
|
|
|
53 |
_10 k β before 2025-08-01 unlocks **WFGY 2.0**._
|
54 |
"""
|
55 |
|
56 |
+
# ββ inference ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
57 |
def run(prompt: str):
|
58 |
p = prompt.strip()
|
59 |
if not p:
|
|
|
64 |
I, G = np.random.randn(2, 256).astype(np.float32)
|
65 |
mod_L = eng.run(I, G, raw_L)
|
66 |
|
67 |
+
m = compare_logits(raw_L, mod_L)
|
68 |
head = f"βΌ var {m['var_drop']*100:.1f}% | KL {m['kl_divergence']:.3f} | top-1 {'kept' if m['top1'] else 'changed'}"
|
69 |
|
70 |
def top5(logits):
|
71 |
p = softmax(logits)
|
72 |
idx = p.argsort()[-5:][::-1]
|
73 |
+
return "\n".join([f\"'{tok.decode(int(i)).strip()}': {p[i]:.2e}\" for i in idx])
|
|
|
74 |
|
75 |
raw_txt = top5(raw_L)
|
76 |
mod_txt = top5(mod_L)
|
|
|
80 |
|
81 |
return raw_txt, mod_txt, head, Image.open(buf)
|
82 |
|
83 |
+
# ββ Gradio UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
84 |
with gr.Blocks(title="WFGY variance-gate demo") as demo:
|
85 |
gr.Markdown(banner)
|
86 |
|