spanofzero commited on
Commit
242ab7a
·
verified ·
1 Parent(s): 059a6e6
Files changed (1) hide show
  1. app.py +27 -20
app.py CHANGED
@@ -2,35 +2,42 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
- # Uses the Hugging Face token you just saved as a secret
6
- HF_TOKEN = os.getenv("KIMI_API_KEY")
7
 
8
- # We'll use a powerful open-source model hosted by Hugging Face
9
  client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct", token=HF_TOKEN)
10
 
11
  def samaran_kernel_chat(message, history):
12
- system_message = "You are the Samaran Kernel. You are a privacy-first AI. Use deep reasoning and be witty."
 
13
 
14
- # Build the prompt
15
- prompt = f"<|system|>\n{system_message}</s>\n"
16
  for user_msg, ai_msg in history:
17
- prompt += f"<|user|>\n{user_msg}</s>\n<|assistant|>\n{ai_msg}</s>\n"
18
- prompt += f"<|user|>\n{message}</s>\n<|assistant|>\n"
 
19
 
20
- # Generate response
21
- response = client.text_generation(prompt, max_new_tokens=512, stream=True)
 
 
 
 
 
 
 
 
 
22
 
23
- partial_message = ""
24
- for token in response:
25
- partial_message += token
26
- yield partial_message
27
-
28
- view = gr.ChatInterface(
29
  fn=samaran_kernel_chat,
30
- title="Samaran Kernel (Privacy-First)",
31
- description="Running on Open-Source Llama-3 via Hugging Face. No 3rd-party corporate data sharing.",
32
- theme="soft"
33
  )
34
 
35
  if __name__ == "__main__":
36
- view.launch()
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
+ # This pulls the 'HF_TOKEN' secret you just saved
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
 
8
+ # Using Llama-3-8B: Fast, smart, and runs on Hugging Face's own servers
9
  client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct", token=HF_TOKEN)
10
 
11
  def samaran_kernel_chat(message, history):
12
+ # The Samaran Personality
13
+ system_message = "You are the Samaran Kernel. A privacy-focused AI collaborator. Be witty, insightful, and clear."
14
 
15
+ # Format the conversation
16
+ messages = [{"role": "system", "content": system_message}]
17
  for user_msg, ai_msg in history:
18
+ messages.append({"role": "user", "content": user_msg})
19
+ messages.append({"role": "assistant", "content": ai_msg})
20
+ messages.append({"role": "user", "content": message})
21
 
22
+ # Stream the response
23
+ response = ""
24
+ for message_chunk in client.chat_completion(
25
+ messages,
26
+ max_tokens=512,
27
+ stream=True,
28
+ ):
29
+ token = message_chunk.choices[0].delta.content
30
+ if token:
31
+ response += token
32
+ yield response
33
 
34
+ # The "T3-Style" User Interface
35
+ demo = gr.ChatInterface(
 
 
 
 
36
  fn=samaran_kernel_chat,
37
+ title="Samaran Kernel",
38
+ description="Privacy-First AI Interface. Your data stays on Hugging Face.",
39
+ theme="glass" # Sleek, modern look
40
  )
41
 
42
  if __name__ == "__main__":
43
+ demo.launch()