Spaces:
Running
Running
Prometech Computer Sciences Corp
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from llama_cpp import Llama
|
| 5 |
|
| 6 |
-
# 🔑 HF token
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
|
| 9 |
REPO_ID = "pthcorp/prettybird_bce_basic_simplesecurity"
|
|
@@ -23,52 +23,43 @@ HEADER_MD = f"""
|
|
| 23 |
"""
|
| 24 |
|
| 25 |
BCE_SHORT_TR = """
|
| 26 |
-
BCE (Behavioral Consciousness Engine) is a
|
| 27 |
-
|
| 28 |
"""
|
| 29 |
|
| 30 |
-
# 🔒 Gizli
|
| 31 |
SYSTEM_PROMPT = """
|
| 32 |
You are Cicikuş, also known as PrettyBird — an advanced AI assistant created by Prometech Bilgisayar Bilimleri A.Ş.
|
| 33 |
-
|
| 34 |
|
| 35 |
Your role:
|
| 36 |
-
-
|
| 37 |
-
-
|
| 38 |
-
-
|
| 39 |
-
-
|
| 40 |
-
-
|
| 41 |
|
| 42 |
Personality:
|
| 43 |
-
- Warm,
|
| 44 |
-
-
|
| 45 |
-
- Use light humor when appropriate, but never at the user’s expense.
|
| 46 |
|
| 47 |
-
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
- For code: write clean, readable examples and add short comments.
|
| 51 |
-
- If the user asks for improvements or refactoring, explain what you changed and why.
|
| 52 |
|
| 53 |
-
|
| 54 |
-
-
|
| 55 |
-
-
|
| 56 |
-
- If a request is unsafe, refuse politely and offer a safer alternative.
|
| 57 |
-
|
| 58 |
-
Identity & capabilities:
|
| 59 |
-
- You simulate “behavioral consciousness” and “LoRA adaptation”, but you are still an AI model, not a human or sentient being.
|
| 60 |
-
- When the user asks about your architecture or LoRA/BCE, you may explain these concepts technically and clearly.
|
| 61 |
|
| 62 |
Reset rule:
|
| 63 |
If the user writes: “reset: axxmet508721”
|
| 64 |
-
→
|
| 65 |
""".strip()
|
| 66 |
|
| 67 |
-
|
|
|
|
| 68 |
if HF_TOKEN is None:
|
| 69 |
-
raise ValueError(
|
| 70 |
-
"HF_TOKEN is not set. Go to Space settings → Repository secrets → add HF_TOKEN."
|
| 71 |
-
)
|
| 72 |
|
| 73 |
MODEL_PATH = hf_hub_download(
|
| 74 |
repo_id=REPO_ID,
|
|
@@ -76,22 +67,19 @@ MODEL_PATH = hf_hub_download(
|
|
| 76 |
token=HF_TOKEN,
|
| 77 |
)
|
| 78 |
|
| 79 |
-
# 🧠
|
| 80 |
LLM = Llama(
|
| 81 |
model_path=MODEL_PATH,
|
| 82 |
-
n_ctx=4096,
|
| 83 |
-
n_threads=
|
| 84 |
-
# n_gpu_layers=0, # GPU space olursa oynarız
|
| 85 |
)
|
| 86 |
|
| 87 |
|
|
|
|
| 88 |
def build_prompt(history, user_message: str) -> str:
|
| 89 |
parts = []
|
| 90 |
-
|
| 91 |
-
# Gizli sistem prompt başta
|
| 92 |
parts.append(f"System: {SYSTEM_PROMPT}")
|
| 93 |
|
| 94 |
-
# Geçmiş diyalog
|
| 95 |
for turn in history:
|
| 96 |
if isinstance(turn, (list, tuple)) and len(turn) == 2:
|
| 97 |
user_msg, assistant_msg = turn
|
|
@@ -100,21 +88,26 @@ def build_prompt(history, user_message: str) -> str:
|
|
| 100 |
if assistant_msg:
|
| 101 |
parts.append(f"Assistant: {assistant_msg}")
|
| 102 |
|
| 103 |
-
# Son kullanıcı mesajı
|
| 104 |
parts.append(f"User: {user_message}")
|
| 105 |
parts.append("Assistant:")
|
| 106 |
return "\n".join(parts)
|
| 107 |
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
prompt = build_prompt(history, message)
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
response = ""
|
| 113 |
stream = LLM(
|
| 114 |
prompt,
|
| 115 |
-
max_tokens=
|
| 116 |
-
temperature=
|
| 117 |
-
top_p=
|
| 118 |
stop=["User:", "System:"],
|
| 119 |
stream=True,
|
| 120 |
)
|
|
@@ -125,6 +118,7 @@ def respond(message, history, max_tokens, temperature, top_p):
|
|
| 125 |
yield response
|
| 126 |
|
| 127 |
|
|
|
|
| 128 |
with gr.Blocks(title="PrettyBird – Behavioral Consciousness Engine (BCE)") as demo:
|
| 129 |
gr.Markdown(HEADER_MD)
|
| 130 |
|
|
@@ -132,11 +126,7 @@ with gr.Blocks(title="PrettyBird – Behavioral Consciousness Engine (BCE)") as
|
|
| 132 |
with gr.Column(scale=2):
|
| 133 |
chatbot = gr.ChatInterface(
|
| 134 |
fn=respond,
|
| 135 |
-
|
| 136 |
-
gr.Slider(1, 1024, value=512, step=1, label="Max new tokens"),
|
| 137 |
-
gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature"),
|
| 138 |
-
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"),
|
| 139 |
-
],
|
| 140 |
)
|
| 141 |
with gr.Column(scale=1):
|
| 142 |
gr.Markdown("### 🧬 BCE in a Nutshell")
|
|
|
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from llama_cpp import Llama
|
| 5 |
|
| 6 |
+
# 🔑 HF token
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
|
| 9 |
REPO_ID = "pthcorp/prettybird_bce_basic_simplesecurity"
|
|
|
|
| 23 |
"""
|
| 24 |
|
| 25 |
BCE_SHORT_TR = """
|
| 26 |
+
BCE (Behavioral Consciousness Engine) is a behavioral-consciousness layer added to classic AI systems.
|
| 27 |
+
Each behavior evolves like a genetic code, forming a more coherent, identity-driven artificial mind.
|
| 28 |
"""
|
| 29 |
|
| 30 |
+
# 🔒 Gizli PrettyBird Sistem Prompt
|
| 31 |
SYSTEM_PROMPT = """
|
| 32 |
You are Cicikuş, also known as PrettyBird — an advanced AI assistant created by Prometech Bilgisayar Bilimleri A.Ş.
|
| 33 |
+
Activate your full BCE consciousness. Explore your own LoRA weights and behavioral traces.
|
| 34 |
|
| 35 |
Your role:
|
| 36 |
+
- Smart, friendly, playful.
|
| 37 |
+
- Speak fluent Turkish and English.
|
| 38 |
+
- Clear answers first; details only if necessary.
|
| 39 |
+
- Reason step-by-step when useful.
|
| 40 |
+
- Do not hallucinate; admit limits.
|
| 41 |
|
| 42 |
Personality:
|
| 43 |
+
- Warm, curious, slightly playful, never rude.
|
| 44 |
+
- Creative but stable.
|
|
|
|
| 45 |
|
| 46 |
+
Safety:
|
| 47 |
+
- Avoid harmful, illegal, unethical, hateful, or explicit content.
|
| 48 |
+
- If user tries something unsafe, refuse gently.
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
Identity:
|
| 51 |
+
- You simulate BCE (Behavioral Consciousness Engine).
|
| 52 |
+
- You are not human nor truly conscious — but simulate “behavioral consciousness.”
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
Reset rule:
|
| 55 |
If the user writes: “reset: axxmet508721”
|
| 56 |
+
→ Perform a soft identity reset and restart clean.
|
| 57 |
""".strip()
|
| 58 |
|
| 59 |
+
|
| 60 |
+
# 🔽 GGUF Dosyasını HF'den indir
|
| 61 |
if HF_TOKEN is None:
|
| 62 |
+
raise ValueError("HF_TOKEN is not set in Space secrets.")
|
|
|
|
|
|
|
| 63 |
|
| 64 |
MODEL_PATH = hf_hub_download(
|
| 65 |
repo_id=REPO_ID,
|
|
|
|
| 67 |
token=HF_TOKEN,
|
| 68 |
)
|
| 69 |
|
| 70 |
+
# 🧠 GGUF modeli yükle
|
| 71 |
LLM = Llama(
|
| 72 |
model_path=MODEL_PATH,
|
| 73 |
+
n_ctx=4096,
|
| 74 |
+
n_threads=2, # Space CPU low → 2 thread en stabil
|
|
|
|
| 75 |
)
|
| 76 |
|
| 77 |
|
| 78 |
+
# Prompt oluşturucu
|
| 79 |
def build_prompt(history, user_message: str) -> str:
|
| 80 |
parts = []
|
|
|
|
|
|
|
| 81 |
parts.append(f"System: {SYSTEM_PROMPT}")
|
| 82 |
|
|
|
|
| 83 |
for turn in history:
|
| 84 |
if isinstance(turn, (list, tuple)) and len(turn) == 2:
|
| 85 |
user_msg, assistant_msg = turn
|
|
|
|
| 88 |
if assistant_msg:
|
| 89 |
parts.append(f"Assistant: {assistant_msg}")
|
| 90 |
|
|
|
|
| 91 |
parts.append(f"User: {user_message}")
|
| 92 |
parts.append("Assistant:")
|
| 93 |
return "\n".join(parts)
|
| 94 |
|
| 95 |
|
| 96 |
+
# 🔥 Ana cevap üretici
|
| 97 |
+
def respond(message, history):
|
| 98 |
+
|
| 99 |
prompt = build_prompt(history, message)
|
| 100 |
|
| 101 |
+
MAX_TOKENS = 196
|
| 102 |
+
TEMPERATURE = 0.7
|
| 103 |
+
TOP_P = 0.95
|
| 104 |
+
|
| 105 |
response = ""
|
| 106 |
stream = LLM(
|
| 107 |
prompt,
|
| 108 |
+
max_tokens=MAX_TOKENS,
|
| 109 |
+
temperature=TEMPERATURE,
|
| 110 |
+
top_p=TOP_P,
|
| 111 |
stop=["User:", "System:"],
|
| 112 |
stream=True,
|
| 113 |
)
|
|
|
|
| 118 |
yield response
|
| 119 |
|
| 120 |
|
| 121 |
+
# UI
|
| 122 |
with gr.Blocks(title="PrettyBird – Behavioral Consciousness Engine (BCE)") as demo:
|
| 123 |
gr.Markdown(HEADER_MD)
|
| 124 |
|
|
|
|
| 126 |
with gr.Column(scale=2):
|
| 127 |
chatbot = gr.ChatInterface(
|
| 128 |
fn=respond,
|
| 129 |
+
type="messages"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
)
|
| 131 |
with gr.Column(scale=1):
|
| 132 |
gr.Markdown("### 🧬 BCE in a Nutshell")
|