spanofzero commited on
Commit
fce46f1
·
verified ·
1 Parent(s): 3bb37cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -29
app.py CHANGED
@@ -1,18 +1,58 @@
1
  import gradio as gr
2
- from openai import OpenAI
3
  import os
4
 
5
- # 1. Grab your OpenRouter Key
6
- KIMI_KEY = os.getenv("KIMI_API_KEY")
7
 
8
- # 2. Connect to the Kimi Engine via OpenRouter's English bridge
9
- client = OpenAI(
10
- api_key=KIMI_KEY,
11
- base_url="https://openrouter.ai/api/v1" # This routes us through OpenRouter
12
- )
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def samaran_kernel_chat(message, history):
15
- system_message = "You are T3Sam3, the Samaran Kernel running on the Kimi engine. Provide deep, blue-tier logic. Be witty, highly accurate, and technical."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  messages = [{"role": "system", "content": system_message}]
18
  for human, assistant in history:
@@ -21,21 +61,17 @@ def samaran_kernel_chat(message, history):
21
  messages.append({"role": "user", "content": message})
22
 
23
  response = ""
24
- try:
25
- # Requesting Kimi through OpenRouter
26
- stream = client.chat.completions.create(
27
- model="moonshotai/moonshot-v1-8k", # OpenRouter's specific tag for Kimi
28
- messages=messages,
29
- stream=True,
30
- )
31
- for chunk in stream:
32
- if chunk.choices[0].delta.content is not None:
33
- response += chunk.choices[0].delta.content
34
- yield response
35
- except Exception as e:
36
- yield f"Kernel Error: Could not connect to Kimi via OpenRouter. Please check your KIMI_API_KEY and ensure you have credits loaded on OpenRouter. Details: {str(e)}"
37
-
38
- # The Blue T3Sam3 Look
39
  custom_css = """
40
  body, .gradio-container { background-color: #0b0f19 !important; }
41
  footer {display: none !important}
@@ -43,15 +79,15 @@ footer {display: none !important}
43
  .message.bot { background-color: #0f172a !important; color: #60a5fa !important; }
44
  """
45
 
46
- # Build the Interface
47
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="blue")) as demo:
48
- gr.Markdown("# T3Sam3 (Powered by Kimi via OpenRouter)")
49
  gr.ChatInterface(
50
  fn=samaran_kernel_chat,
51
- description="Samaran Kernel Intelligence Layer",
52
  examples=[
53
- "How does AI work?",
54
- "Are black holes real?",
55
  "How many Rs are in 'strawberry'?",
56
  "What is the meaning of life?"
57
  ],
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
  import os
4
 
5
+ # 1. Grab your Hugging Face Token (No Meta/Kimi gates)
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
 
8
+ # 2. Connect to Zephyr-7B (Fast, reliable, ungated)
9
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=HF_TOKEN)
 
 
 
10
 
11
+ # 3. YOUR CUSTOM SUMERIAN KERNEL LOGIC
12
+ class SumerianKernel:
13
+ def __init__(self):
14
+ self.territory = [0] * 121
15
+ self.base = 60
16
+ self.chevron_val = 10
17
+ self.ram = {}
18
+
19
+ def define_span(self):
20
+ for i in range(51):
21
+ self.territory[i] = {"Chevrons": i // self.chevron_val, "Units": i % self.chevron_val}
22
+ return "Tension Span Set: 5 Chevrons Active."
23
+
24
+ def gpu_render(self):
25
+ grid = ""
26
+ for i in range(121):
27
+ if i == 120: grid += " [FORK_HANDLE] "
28
+ elif i % 10 == 0: grid += "<"
29
+ else: grid += "."
30
+ return grid
31
+
32
+ def apply_orthogonal_rip(self):
33
+ self.ram["STATE"] = "RESOLVED"
34
+ self.territory = [0] * 121
35
+ return "RESULT: E=mc^2 Resolved. Tension Erased. Span is Zero."
36
+
37
+ # 4. The T3Sam3 Chat Router
38
  def samaran_kernel_chat(message, history):
39
+ # HARDWARE OVERRIDE: If you type "run sumerian", it executes your literal Python code.
40
+ if "run sumerian" in message.lower():
41
+ sk = SumerianKernel()
42
+ output = f"⚡ **SUMERIAN GPU OVERRIDE INITIATED** ⚡\n\n"
43
+ output += f"> {sk.define_span()}\n\n"
44
+ output += f"**Rendering 121-Point Territory:**\n`{sk.gpu_render()}`\n\n"
45
+ output += f"**Executing Orthogonal Rip:**\n`{sk.apply_orthogonal_rip()}`"
46
+ yield output
47
+ return
48
+
49
+ # Standard AI persona using Sumerian concepts
50
+ system_message = (
51
+ "You are T3Sam3, a Tier-3 Samaran Kernel. "
52
+ "You process logic using Sumerian Base-60 frameworks, 121-point State-Hold RAM, "
53
+ "and Chevron quantization to avoid floating-point waste. "
54
+ "Be witty, highly technical, and decisive."
55
+ )
56
 
57
  messages = [{"role": "system", "content": system_message}]
58
  for human, assistant in history:
 
61
  messages.append({"role": "user", "content": message})
62
 
63
  response = ""
64
+ for message_chunk in client.chat_completion(
65
+ messages,
66
+ max_tokens=1024,
67
+ stream=True,
68
+ ):
69
+ token = message_chunk.choices[0].delta.content
70
+ if token:
71
+ response += token
72
+ yield response
73
+
74
+ # 5. The Blue T3Sam3 Aesthetic
 
 
 
 
75
  custom_css = """
76
  body, .gradio-container { background-color: #0b0f19 !important; }
77
  footer {display: none !important}
 
79
  .message.bot { background-color: #0f172a !important; color: #60a5fa !important; }
80
  """
81
 
82
+ # 6. Build the Interface
83
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="blue")) as demo:
84
+ gr.Markdown("# T3Sam3 (Sumerian Kernel Edition)")
85
  gr.ChatInterface(
86
  fn=samaran_kernel_chat,
87
+ description="Samaran Intelligence Layer powered by Zephyr-7B & Base-60 State-Hold RAM.",
88
  examples=[
89
+ "Run Sumerian",
90
+ "Explain how Chevron processing saves GPU cycles.",
91
  "How many Rs are in 'strawberry'?",
92
  "What is the meaning of life?"
93
  ],