Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import time
|
|
| 8 |
# Securely retrieve the token from your Space's secrets
|
| 9 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
|
| 11 |
-
# Initialize BOTH engines with the
|
| 12 |
client_primary = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 13 |
client_competitor = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 14 |
|
|
@@ -21,32 +21,17 @@ class StateController:
|
|
| 21 |
self._batch = 10
|
| 22 |
self._reg = {}
|
| 23 |
self._rendered = self._build_render()
|
| 24 |
-
|
| 25 |
-
self._rom60 = tuple(
|
| 26 |
-
tuple((i * j) % 60 for j in range(60))
|
| 27 |
-
for i in range(60)
|
| 28 |
-
)
|
| 29 |
self._symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567"
|
| 30 |
|
| 31 |
def _build_render(self) -> str:
|
| 32 |
-
return "".join(
|
| 33 |
-
" [NODE_120] " if i == 120 else ("<" if i % 10 == 0 else ".")
|
| 34 |
-
for i in range(121)
|
| 35 |
-
)
|
| 36 |
|
| 37 |
def diagnostic(self) -> str:
|
| 38 |
-
for i in range(51):
|
| 39 |
-
self._state[i] = i % self._batch
|
| 40 |
self._reg.clear()
|
| 41 |
self._reg["STATUS"] = "RESOLVED"
|
| 42 |
-
return
|
| 43 |
-
"Diagnostic sequence initiated.\n\n"
|
| 44 |
-
"Grid initialized: 5 active blocks.\n\n"
|
| 45 |
-
"Rendering 121-point array:\n"
|
| 46 |
-
f"{self._rendered}\n\n"
|
| 47 |
-
"Executing state resolution:\n"
|
| 48 |
-
"System resolved. State array reset to zero."
|
| 49 |
-
)
|
| 50 |
|
| 51 |
def generate_receipt(self, a: int, b: int, c: int) -> str:
|
| 52 |
rom_val = self._rom60[a % 60][b % 60]
|
|
@@ -54,106 +39,86 @@ class StateController:
|
|
| 54 |
return f"0{self._symbols[checksum_index]}"
|
| 55 |
|
| 56 |
def validate_receipt(self, receipt: str, a: int, b: int, c: int) -> str:
|
| 57 |
-
|
| 58 |
-
if receipt == expected_receipt:
|
| 59 |
self._state[120] = 1
|
| 60 |
-
return f"[NODE_120: ACTIVE] Checksum Validated. Receipt {receipt} matches
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
return f"[NODE_120: INACTIVE] Verification Failed. Expected receipt {expected_receipt}, received {receipt}."
|
| 64 |
|
| 65 |
controller = StateController()
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
def generate_responses(user_message, primary_history, competitor_history):
|
| 71 |
-
clean_message = user_message.strip()
|
| 72 |
-
if not clean_message:
|
| 73 |
-
yield primary_history, competitor_history, ""
|
| 74 |
-
return
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
competitor_history.append({"role": "user", "content": clean_message})
|
| 80 |
-
competitor_history.append({"role": "assistant", "content": ""})
|
| 81 |
-
yield primary_history, competitor_history, ""
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
competitor_history[-1]["content"] = "Hardware diagnostics not supported by generic models."
|
| 90 |
-
yield primary_history, competitor_history, ""
|
| 91 |
-
return
|
| 92 |
|
| 93 |
-
#
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
primary_history[-1]["content"] = f"{output}\n\n---\n*Telemetry: {time.perf_counter()-start_time:.6f}s | Source: Local ROM Math*"
|
| 99 |
-
competitor_history[-1]["content"] = "Deterministic verification not supported."
|
| 100 |
-
yield primary_history, competitor_history, ""
|
| 101 |
return
|
| 102 |
|
| 103 |
-
# 1.
|
| 104 |
try:
|
| 105 |
-
msgs = [
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
except Exception as e:
|
| 115 |
-
|
| 116 |
-
yield primary_history, competitor_history, ""
|
| 117 |
|
| 118 |
-
# 2.
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
yield
|
| 122 |
|
| 123 |
try:
|
| 124 |
-
msgs = [
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
| 133 |
except Exception as e:
|
| 134 |
-
|
| 135 |
-
|
|
|
|
| 136 |
|
| 137 |
-
custom_css = ""
|
| 138 |
-
body, .gradio-container { background-color: #110c08 !important; }
|
| 139 |
-
footer {display: none !important}
|
| 140 |
-
"""
|
| 141 |
|
| 142 |
-
with gr.Blocks() as demo:
|
| 143 |
gr.Markdown("# [ GLYPH.IO ]\n### Dual-Engine Hardware Benchmark")
|
| 144 |
-
|
| 145 |
-
primary_chat = gr.Chatbot(label="Augmented Logic Kernel", height=320, type="messages")
|
| 146 |
-
|
| 147 |
with gr.Row():
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
gr.
|
| 152 |
-
|
| 153 |
-
competitor_chat = gr.Chatbot(label="Vanilla Qwen 2.5", height=320, type="messages")
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
|
| 158 |
if __name__ == "__main__":
|
| 159 |
-
demo.queue().launch(
|
|
|
|
| 8 |
# Securely retrieve the token from your Space's secrets
|
| 9 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
|
| 11 |
+
# Initialize BOTH engines with the same model
|
| 12 |
client_primary = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 13 |
client_competitor = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 14 |
|
|
|
|
| 21 |
self._batch = 10
|
| 22 |
self._reg = {}
|
| 23 |
self._rendered = self._build_render()
|
| 24 |
+
self._rom60 = tuple(tuple((i * j) % 60 for j in range(60)) for i in range(60))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
self._symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567"
|
| 26 |
|
| 27 |
def _build_render(self) -> str:
|
| 28 |
+
return "".join(" [NODE_120] " if i == 120 else ("<" if i % 10 == 0 else ".") for i in range(121))
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
def diagnostic(self) -> str:
|
| 31 |
+
for i in range(51): self._state[i] = i % self._batch
|
|
|
|
| 32 |
self._reg.clear()
|
| 33 |
self._reg["STATUS"] = "RESOLVED"
|
| 34 |
+
return f"Diagnostic sequence initiated.\n\nGrid initialized.\n\n{self._rendered}\n\nSystem resolved."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
def generate_receipt(self, a: int, b: int, c: int) -> str:
|
| 37 |
rom_val = self._rom60[a % 60][b % 60]
|
|
|
|
| 39 |
return f"0{self._symbols[checksum_index]}"
|
| 40 |
|
| 41 |
def validate_receipt(self, receipt: str, a: int, b: int, c: int) -> str:
|
| 42 |
+
if receipt == self.generate_receipt(a, b, c):
|
|
|
|
| 43 |
self._state[120] = 1
|
| 44 |
+
return f"[NODE_120: ACTIVE] Checksum Validated. Receipt {receipt} matches."
|
| 45 |
+
self._state[120] = 0
|
| 46 |
+
return f"[NODE_120: INACTIVE] Verification Failed."
|
|
|
|
| 47 |
|
| 48 |
controller = StateController()
|
| 49 |
|
| 50 |
+
PRIMARY_SYS = {"role": "system", "content": "You are a logic-focused inference engine. Use strict state-hold memory."}
|
| 51 |
+
VANILLA_SYS = {"role": "system", "content": "You are a standard helpful AI assistant."}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
def generate_responses(message, p_history, c_history):
|
| 54 |
+
msg = message.strip()
|
| 55 |
+
if not msg: yield p_history, c_history, ""
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# Revert to standard List-of-Lists format
|
| 58 |
+
p_history.append([msg, ""])
|
| 59 |
+
c_history.append([msg, ""])
|
| 60 |
+
yield p_history, c_history, ""
|
| 61 |
+
|
| 62 |
+
start = time.perf_counter()
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
# Logic Intercepts
|
| 65 |
+
if msg.lower() == "run grid diagnostic":
|
| 66 |
+
p_history[-1][1] = f"{controller.diagnostic()}\n\n---\n*Telemetry: {time.perf_counter()-start:.4f}s*"
|
| 67 |
+
c_history[-1][1] = "Hardware diagnostics not supported."
|
| 68 |
+
yield p_history, c_history, ""
|
|
|
|
|
|
|
|
|
|
| 69 |
return
|
| 70 |
|
| 71 |
+
# 1. Primary Engine
|
| 72 |
try:
|
| 73 |
+
msgs = [PRIMARY_SYS]
|
| 74 |
+
for h in p_history[:-1]:
|
| 75 |
+
msgs.extend([{"role": "user", "content": h[0]}, {"role": "assistant", "content": h[1]}])
|
| 76 |
+
msgs.append({"role": "user", "content": msg})
|
| 77 |
+
|
| 78 |
+
res = ""
|
| 79 |
+
for chunk in client_primary.chat_completion(messages=msgs, max_tokens=1024, stream=True, temperature=0.1):
|
| 80 |
+
res += (chunk.choices[0].delta.content or "")
|
| 81 |
+
p_history[-1][1] = res
|
| 82 |
+
yield p_history, c_history, ""
|
| 83 |
+
p_history[-1][1] += f"\n\n---\n*Telemetry: {time.perf_counter()-start:.2f}s | Augmented*"
|
| 84 |
except Exception as e:
|
| 85 |
+
p_history[-1][1] = f"Error: {str(e)}"
|
|
|
|
| 86 |
|
| 87 |
+
# 2. Competitor Engine
|
| 88 |
+
c_start = time.perf_counter()
|
| 89 |
+
c_history[-1][1] = "*Connecting...*"
|
| 90 |
+
yield p_history, c_history, ""
|
| 91 |
|
| 92 |
try:
|
| 93 |
+
msgs = [VANILLA_SYS]
|
| 94 |
+
for h in c_history[:-1]:
|
| 95 |
+
msgs.extend([{"role": "user", "content": h[0]}, {"role": "assistant", "content": h[1]}])
|
| 96 |
+
msgs.append({"role": "user", "content": msg})
|
| 97 |
+
|
| 98 |
+
res = ""
|
| 99 |
+
for chunk in client_competitor.chat_completion(messages=msgs, max_tokens=1024, stream=True, temperature=0.7):
|
| 100 |
+
res += (chunk.choices[0].delta.content or "")
|
| 101 |
+
c_history[-1][1] = res
|
| 102 |
+
yield p_history, c_history, ""
|
| 103 |
+
c_history[-1][1] += f"\n\n---\n*Telemetry: {time.perf_counter()-c_start:.2f}s | Vanilla*"
|
| 104 |
except Exception as e:
|
| 105 |
+
c_history[-1][1] = f"Error: {str(e)}"
|
| 106 |
+
|
| 107 |
+
yield p_history, c_history, ""
|
| 108 |
|
| 109 |
+
custom_css = "body, .gradio-container { background-color: #110c08 !important; } footer {display: none !important}"
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange"), css=custom_css) as demo:
|
| 112 |
gr.Markdown("# [ GLYPH.IO ]\n### Dual-Engine Hardware Benchmark")
|
| 113 |
+
p_chat = gr.Chatbot(label="Augmented Logic Kernel", height=320)
|
|
|
|
|
|
|
| 114 |
with gr.Row():
|
| 115 |
+
txt = gr.Textbox(label="Message", placeholder="Enter task...", scale=8)
|
| 116 |
+
btn = gr.Button("Execute", scale=1, variant="primary")
|
| 117 |
+
gr.Examples(examples=["Calculate the integer distribution for 120 units across 3 nodes.", "Run grid diagnostic"], inputs=txt)
|
| 118 |
+
c_chat = gr.Chatbot(label="Vanilla Qwen 2.5", height=320)
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
txt.submit(generate_responses, [txt, p_chat, c_chat], [p_chat, c_chat, txt])
|
| 121 |
+
btn.click(generate_responses, [txt, p_chat, c_chat], [p_chat, c_chat, txt])
|
| 122 |
|
| 123 |
if __name__ == "__main__":
|
| 124 |
+
demo.queue().launch()
|