Spaces:
Runtime error
Runtime error
test1
Browse files
app.py
CHANGED
|
@@ -2,35 +2,42 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
HF_TOKEN = os.getenv("
|
| 7 |
|
| 8 |
-
#
|
| 9 |
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct", token=HF_TOKEN)
|
| 10 |
|
| 11 |
def samaran_kernel_chat(message, history):
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
for user_msg, ai_msg in history:
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
response =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
partial_message += token
|
| 26 |
-
yield partial_message
|
| 27 |
-
|
| 28 |
-
view = gr.ChatInterface(
|
| 29 |
fn=samaran_kernel_chat,
|
| 30 |
-
title="Samaran Kernel
|
| 31 |
-
description="
|
| 32 |
-
theme="
|
| 33 |
)
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
-
|
|
|
|
| 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()
|