Spaces:
Runtime error
Runtime error
Glyph.io
Browse filesThe fastest Ai with manager
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from huggingface_hub import InferenceClient
|
|
| 3 |
from array import array
|
| 4 |
import os
|
| 5 |
import re
|
|
|
|
| 6 |
|
| 7 |
# Securely retrieve the token from Space secrets
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
@@ -11,7 +12,6 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
| 11 |
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 12 |
|
| 13 |
class StateController:
|
| 14 |
-
# Added _rom60 and _symbols to memory-efficient slots
|
| 15 |
__slots__ = ("_state", "_metric", "_batch", "_reg", "_rendered", "_rom60", "_symbols")
|
| 16 |
|
| 17 |
def __init__(self):
|
|
@@ -81,24 +81,27 @@ SYSTEM_MSG = {
|
|
| 81 |
}
|
| 82 |
|
| 83 |
def generate_response(message: str, history: list):
|
|
|
|
| 84 |
msg_lower = message.lower().strip()
|
| 85 |
|
| 86 |
# Hardware diagnostic intercept
|
| 87 |
if msg_lower == "run grid diagnostic":
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
return
|
| 90 |
|
| 91 |
# Deterministic Checksum Intercept (Bypasses AI completely)
|
| 92 |
-
# Looks for format: "Verify receipt 0K for 60, 30, 30"
|
| 93 |
verify_match = re.match(r"verify receipt\s+([a-zA-Z0-9]{2})\s+for\s+(\d+),\s*(\d+),\s*(\d+)", msg_lower, re.IGNORECASE)
|
| 94 |
if verify_match:
|
| 95 |
-
receipt = verify_match.group(1)
|
| 96 |
-
# Re-adjust original case from input
|
| 97 |
-
receipt = verify_match.group(1)
|
| 98 |
a = int(verify_match.group(2))
|
| 99 |
b = int(verify_match.group(3))
|
| 100 |
c = int(verify_match.group(4))
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
return
|
| 103 |
|
| 104 |
# Build the message list for inference
|
|
@@ -121,6 +124,16 @@ def generate_response(message: str, history: list):
|
|
| 121 |
token = chunk.choices[0].delta.content or ""
|
| 122 |
partial_response += token
|
| 123 |
yield partial_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
except Exception as exc:
|
| 125 |
yield f"System Error: {str(exc)}. Verify API token and permissions."
|
| 126 |
|
|
|
|
| 3 |
from array import array
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
# Securely retrieve the token from Space secrets
|
| 9 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
| 12 |
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
| 13 |
|
| 14 |
class StateController:
|
|
|
|
| 15 |
__slots__ = ("_state", "_metric", "_batch", "_reg", "_rendered", "_rom60", "_symbols")
|
| 16 |
|
| 17 |
def __init__(self):
|
|
|
|
| 81 |
}
|
| 82 |
|
| 83 |
def generate_response(message: str, history: list):
|
| 84 |
+
start_time = time.perf_counter()
|
| 85 |
msg_lower = message.lower().strip()
|
| 86 |
|
| 87 |
# Hardware diagnostic intercept
|
| 88 |
if msg_lower == "run grid diagnostic":
|
| 89 |
+
output = controller.diagnostic()
|
| 90 |
+
elapsed_time = time.perf_counter() - start_time
|
| 91 |
+
yield f"{output}\n\n---\n*Telemetry: Compute Time {elapsed_time:.4f}s | Source: Local Engine*"
|
| 92 |
return
|
| 93 |
|
| 94 |
# Deterministic Checksum Intercept (Bypasses AI completely)
|
|
|
|
| 95 |
verify_match = re.match(r"verify receipt\s+([a-zA-Z0-9]{2})\s+for\s+(\d+),\s*(\d+),\s*(\d+)", msg_lower, re.IGNORECASE)
|
| 96 |
if verify_match:
|
| 97 |
+
receipt = verify_match.group(1)
|
|
|
|
|
|
|
| 98 |
a = int(verify_match.group(2))
|
| 99 |
b = int(verify_match.group(3))
|
| 100 |
c = int(verify_match.group(4))
|
| 101 |
+
|
| 102 |
+
output = controller.validate_receipt(receipt, a, b, c)
|
| 103 |
+
elapsed_time = time.perf_counter() - start_time
|
| 104 |
+
yield f"{output}\n\n---\n*Telemetry: Compute Time {elapsed_time:.6f}s | Source: Local ROM Math*"
|
| 105 |
return
|
| 106 |
|
| 107 |
# Build the message list for inference
|
|
|
|
| 124 |
token = chunk.choices[0].delta.content or ""
|
| 125 |
partial_response += token
|
| 126 |
yield partial_response
|
| 127 |
+
|
| 128 |
+
# Post-processing telemetry after the stream completes
|
| 129 |
+
elapsed_time = time.perf_counter() - start_time
|
| 130 |
+
word_count = len(partial_response.split())
|
| 131 |
+
est_speed = word_count / elapsed_time if elapsed_time > 0 else 0
|
| 132 |
+
|
| 133 |
+
# Append telemetry footer to the final response
|
| 134 |
+
final_output = partial_response + f"\n\n---\n*Telemetry: Compute Time {elapsed_time:.2f}s | Est. Speed: {est_speed:.2f} words/sec | Source: Inference API*"
|
| 135 |
+
yield final_output
|
| 136 |
+
|
| 137 |
except Exception as exc:
|
| 138 |
yield f"System Error: {str(exc)}. Verify API token and permissions."
|
| 139 |
|