spanofzero commited on
Commit
97f62e3
·
verified ·
1 Parent(s): 94155c0

Update appy.app

Browse files
Files changed (1) hide show
  1. appy.app +159 -0
appy.app CHANGED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ from array import array
4
+ from functools import lru_cache
5
+ import os, re, time
6
+
7
+ # 1. API Configuration - Upgraded to the massive 72B Model
8
+ HF_TOKEN = os.getenv("HF_TOKEN")
9
+ MODEL_ID = "Qwen/Qwen2.5-72B-Instruct"
10
+ client = InferenceClient(MODEL_ID, token=HF_TOKEN)
11
+
12
+ # 2. T3 High-Speed Logic Kernel
13
+ class StateController:
14
+ __slots__ = ("_state", "_rom60", "_symbols", "_rendered")
15
+ def __init__(self):
16
+ self._state = array("B", [0]) * 121
17
+ self._rom60 = tuple(tuple((i * j) % 60 for j in range(60)) for i in range(60))
18
+ self._symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567"
19
+ self._rendered = "".join(" [NODE_120] " if i == 120 else ("<" if i % 10 == 0 else ".") for i in range(121))
20
+
21
+ @lru_cache(maxsize=128)
22
+ def compute_distribution(self, total, nodes) -> str:
23
+ if nodes <= 0: return "Error: Node count must be positive."
24
+ base, rem = divmod(total, nodes)
25
+ res = f"T3 Logic Kernel resolved {total} units across {nodes} nodes:\n\n"
26
+ for i in range(nodes):
27
+ res += f"NODE_{i+1:02}: {base + (1 if i < rem else 0)} units\n"
28
+ return res
29
+
30
+ def get_glyphs(self) -> str:
31
+ return f"Rendering 121-point state array:\n\n{self._rendered}\n\nSystem State: RESOLVED"
32
+
33
+ def generate_receipt(self, a, b, c) -> str:
34
+ idx = (self._rom60[a % 60][b % 60] ^ (c % 60)) % 60
35
+ return f"0{self._symbols[idx]}"
36
+
37
+ def validate_receipt(self, receipt, a, b, c) -> str:
38
+ expected = self.generate_receipt(a, b, c)
39
+ if receipt == expected:
40
+ return f"√ CHECKSUM VALID: Receipt {receipt} verified for allocation ({a}, {b}, {c})."
41
+ return f"× CHECKSUM INVALID: Expected {expected}, received {receipt}."
42
+
43
+ controller = StateController()
44
+
45
+ # THE UPGRADE: Dynamic Telemetry Formatting
46
+ def format_telemetry(seconds: float) -> str:
47
+ if seconds < 0.001: return f"{seconds * 1_000_000:.2f} \u03BCs"
48
+ return f"{seconds * 1_000:.2f} ms" if seconds < 1 else f"{seconds:.2f} s"
49
+
50
+ # 3. Core Response Logic
51
+ def generate_responses(user_message, p_hist, c_hist):
52
+ msg = user_message.strip()
53
+ if not msg: yield p_hist or [], c_hist or [], ""; return
54
+
55
+ p_hist, c_hist = p_hist or [], c_hist or []
56
+ p_hist.append({"role": "user", "content": msg})
57
+ p_hist.append({"role": "assistant", "content": ""})
58
+ c_hist.append({"role": "user", "content": msg})
59
+ c_hist.append({"role": "assistant", "content": ""})
60
+ yield p_hist, c_hist, ""
61
+
62
+ start_time = time.perf_counter()
63
+
64
+ # --- LOCAL INTERCEPTORS ---
65
+ dist_match = re.search(r"(\d+)\s+units\s+across\s+(\d+)\s+nodes", msg, re.IGNORECASE)
66
+ diag_match = any(kw in msg.lower() for kw in ["diagnostic", "grid"])
67
+ rcpt_match = re.search(r"verify receipt\s+([a-zA-Z0-9]{2})\s+for\s+(\d+),\s*(\d+),\s*(\d+)", msg, re.IGNORECASE)
68
+
69
+ if dist_match or diag_match or rcpt_match:
70
+ if dist_match:
71
+ res = controller.compute_distribution(int(dist_match.group(1)), int(dist_match.group(2)))
72
+ elif rcpt_match:
73
+ res = controller.validate_receipt(rcpt_match.group(1), int(rcpt_match.group(2)), int(rcpt_match.group(3)), int(rcpt_match.group(4)))
74
+ else:
75
+ res = controller.get_glyphs()
76
+
77
+ elapsed = time.perf_counter() - start_time
78
+ p_hist[-1]["content"] = f"{res}\n\n---\n*Telemetry: {format_telemetry(elapsed)} | Source: LOCAL T3 KERNEL*"
79
+ yield p_hist, c_hist, ""
80
+ else:
81
+ try:
82
+ res_text = ""
83
+ stream = client.chat_completion(
84
+ messages=[{"role":"system","content":"T3 Augmented Logic Engine"}] + p_hist[:-1],
85
+ max_tokens=512, stream=True, temperature=0.1
86
+ )
87
+ for chunk in stream:
88
+ res_text += (chunk.choices[0].delta.content or "")
89
+ p_hist[-1]["content"] = res_text
90
+ yield p_hist, c_hist, ""
91
+ p_hist[-1]["content"] += f"\n\n---\n*Telemetry: {format_telemetry(time.perf_counter()-start_time)} | Source: AUGMENTED CLOUD*"
92
+ yield p_hist, c_hist, ""
93
+ except Exception as e:
94
+ p_hist[-1]["content"] = f"Primary Error: {str(e)}"
95
+ yield p_hist, c_hist, ""
96
+
97
+ comp_start = time.perf_counter()
98
+ c_hist[-1]["content"] = "*Routing through heavy 72B infrastructure...*"
99
+ yield p_hist, c_hist, ""
100
+
101
+ try:
102
+ res_text = ""
103
+ stream = client.chat_completion(
104
+ messages=[{"role":"system","content":"Vanilla AI"}] + c_hist[:-1],
105
+ max_tokens=512, stream=True, temperature=0.7
106
+ )
107
+ for chunk in stream:
108
+ res_text += (chunk.choices[0].delta.content or "")
109
+ c_hist[-1]["content"] = res_text
110
+ yield p_hist, c_hist, ""
111
+ c_hist[-1]["content"] += f"\n\n---\n*Telemetry: {format_telemetry(time.perf_counter()-comp_start)} | Source: VANILLA CLOUD*"
112
+ yield p_hist, c_hist, ""
113
+ except Exception as e:
114
+ c_hist[-1]["content"] = f"Competitor Error: {str(e)}"
115
+ yield p_hist, c_hist, ""
116
+
117
+ # 4. Interface Build (With Scrollable Examples)
118
+ custom_css = """
119
+ body, .gradio-container { background-color: #110c08 !important; color: #fb923c !important; }
120
+ footer { display: none !important; }
121
+ #scrollable-box { max-height: 160px; overflow-y: auto; border: 1px solid #333; padding: 5px; border-radius: 8px; margin-bottom: 10px; }
122
+ """
123
+
124
+ example_prompts = [
125
+ ["Run grid diagnostic"],
126
+ ["Calculate the integer distribution for 50000 units across 12 nodes."],
127
+ ["Define P vs. NP. Then validate a 120-unit distribution across 3 nodes."],
128
+ ["Execute a Tier-3 Distribution Audit for 8593 units across 14 nodes."],
129
+ ["Verify receipt 0e for 60, 30, 30"],
130
+ ["Distribute 1000000 units across 7 nodes."],
131
+ ["Perform a hardware grid initialization and diagnostic check."],
132
+ ["Allocate exactly 2048 units across 16 nodes for cluster balancing."],
133
+ ["Explain the theory of relativity. Then process 999 units across 9 nodes."],
134
+ ["Run a full system diagnostic on the logical array."],
135
+ ["Load balance 123456789 units across 256 nodes."],
136
+ ["Draft an email to the logistics team. Then route 400 units across 5 nodes."],
137
+ ["Initialize grid memory matrix and verify logic gate alignment."],
138
+ ["Evaluate node efficiency for 7777 units across 11 nodes."],
139
+ ["Explain how standard AI struggles with deterministic mathematical verification."]
140
+ ]
141
+
142
+ with gr.Blocks() as demo:
143
+ gr.Markdown("# [ GLYPH.IO ]\n### Dual-Engine Hardware Benchmark")
144
+ p_chat = gr.Chatbot(label="Augmented Logic Kernel (T3 Architecture)", height=350)
145
+
146
+ with gr.Row():
147
+ msg_in = gr.Textbox(label="Message", placeholder="Test P vs NP or Logistics Distribution...", scale=8)
148
+ submit_btn = gr.Button("Execute", scale=1, variant="primary")
149
+
150
+ with gr.Column(elem_id="scrollable-box"):
151
+ gr.Examples(examples=example_prompts, inputs=msg_in, label="Diagnostic Test Suite (Scroll for more)")
152
+
153
+ c_chat = gr.Chatbot(label="Vanilla Qwen 2.5 72B (Standard Infrastructure)", height=350)
154
+
155
+ msg_in.submit(generate_responses, [msg_in, p_chat, c_chat], [p_chat, c_chat, msg_in])
156
+ submit_btn.click(generate_responses, [msg_in, p_chat, c_chat], [p_chat, c_chat, msg_in])
157
+
158
+ if __name__ == "__main__":
159
+ demo.queue().launch(theme=gr.themes.Soft(primary_hue="orange"), css=custom_css)