Spaces:
Running
Running
Prometech Computer Sciences Corp
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,13 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from huggingface_hub import
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
LOGO_URL = "https://prometech.net.tr/wp-content/uploads/2025/10/pthheader.png"
|
|
@@ -18,17 +23,6 @@ HEADER_MD = f"""
|
|
| 18 |
<em>Gerçek yapay zeka evrimine hoş geldiniz.</em>
|
| 19 |
</p>
|
| 20 |
|
| 21 |
-
---
|
| 22 |
-
|
| 23 |
-
### 🧠 What is PrettyBird?
|
| 24 |
-
|
| 25 |
-
PrettyBird is powered by the <strong>Behavioral Consciousness Engine (BCE)</strong>, an architecture that simulates partial, behavior-level consciousness in AI systems.
|
| 26 |
-
|
| 27 |
-
Instead of only mapping inputs to outputs, PrettyBird:
|
| 28 |
-
- considers its internal state, history, and context,
|
| 29 |
-
- evolves behavior patterns over time,
|
| 30 |
-
- aims for higher consistency, identity and alignment.
|
| 31 |
-
|
| 32 |
---
|
| 33 |
"""
|
| 34 |
|
|
@@ -40,7 +34,6 @@ BCE, tam anlamıyla insan bilinci değildir; ancak sistemin kendi içsel durumu,
|
|
| 40 |
“davranışsal bilinç” veya “kısmi bilinç” olarak yorumlanabilir.
|
| 41 |
"""
|
| 42 |
|
| 43 |
-
|
| 44 |
SYSTEM_PROMPT = """
|
| 45 |
You are Cicikuş, also known as PrettyBird — an advanced AI assistant created by Prometech Bilgisayar Bilimleri A.Ş.
|
| 46 |
|
|
@@ -77,54 +70,62 @@ If the user writes: “reset: axxmet508721”
|
|
| 77 |
""".strip()
|
| 78 |
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
system_message = (system_message or "").strip()
|
| 84 |
if system_message:
|
| 85 |
-
|
| 86 |
|
| 87 |
-
# history: [(user, assistant), ...]
|
| 88 |
for turn in history:
|
| 89 |
if isinstance(turn, (list, tuple)) and len(turn) == 2:
|
| 90 |
user_msg, assistant_msg = turn
|
| 91 |
if user_msg:
|
| 92 |
-
|
| 93 |
if assistant_msg:
|
| 94 |
-
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 101 |
-
|
| 102 |
-
raise ValueError(
|
| 103 |
-
"HF_TOKEN is not set. Go to your Space settings → Repository secrets → add HF_TOKEN."
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
-
client = InferenceClient(
|
| 107 |
-
model="pthcorp/prettybird_bce_basic_vl",
|
| 108 |
-
token=HF_TOKEN,
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
messages = build_messages(system_message, history, message)
|
| 112 |
|
| 113 |
response = ""
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
for chunk in client.chat_completion(
|
| 117 |
-
messages=messages,
|
| 118 |
max_tokens=int(max_tokens),
|
| 119 |
temperature=float(temperature),
|
| 120 |
top_p=float(top_p),
|
|
|
|
| 121 |
stream=True,
|
| 122 |
-
)
|
| 123 |
-
token = ""
|
| 124 |
-
choices = getattr(chunk, "choices", None)
|
| 125 |
-
if choices and choices[0].delta and choices[0].delta.content:
|
| 126 |
-
token = choices[0].delta.content
|
| 127 |
|
|
|
|
|
|
|
|
|
|
| 128 |
response += token
|
| 129 |
yield response
|
| 130 |
|
|
@@ -142,15 +143,9 @@ with gr.Blocks(title="PrettyBird – Behavioral Consciousness Engine (BCE)") as
|
|
| 142 |
label="System message",
|
| 143 |
lines=6,
|
| 144 |
),
|
| 145 |
-
gr.Slider(1,
|
| 146 |
-
gr.Slider(0.1,
|
| 147 |
-
gr.Slider(
|
| 148 |
-
0.1,
|
| 149 |
-
1.0,
|
| 150 |
-
value=0.95,
|
| 151 |
-
step=0.05,
|
| 152 |
-
label="Top-p (nucleus sampling)",
|
| 153 |
-
),
|
| 154 |
],
|
| 155 |
)
|
| 156 |
with gr.Column(scale=1):
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
from llama_cpp import Llama
|
| 5 |
|
| 6 |
+
# 🔑 Hugging Face token (gated repo için şart)
|
| 7 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
+
|
| 9 |
+
REPO_ID = "pthcorp/prettybird_bce_basic_vl"
|
| 10 |
+
MODEL_FILENAME = "prettybird_bce_basic_vl.gguf"
|
| 11 |
|
| 12 |
|
| 13 |
LOGO_URL = "https://prometech.net.tr/wp-content/uploads/2025/10/pthheader.png"
|
|
|
|
| 23 |
<em>Gerçek yapay zeka evrimine hoş geldiniz.</em>
|
| 24 |
</p>
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
---
|
| 27 |
"""
|
| 28 |
|
|
|
|
| 34 |
“davranışsal bilinç” veya “kısmi bilinç” olarak yorumlanabilir.
|
| 35 |
"""
|
| 36 |
|
|
|
|
| 37 |
SYSTEM_PROMPT = """
|
| 38 |
You are Cicikuş, also known as PrettyBird — an advanced AI assistant created by Prometech Bilgisayar Bilimleri A.Ş.
|
| 39 |
|
|
|
|
| 70 |
""".strip()
|
| 71 |
|
| 72 |
|
| 73 |
+
# 🔽 GGUF'i runtime'da HF'den indir
|
| 74 |
+
if HF_TOKEN is None:
|
| 75 |
+
raise ValueError(
|
| 76 |
+
"HF_TOKEN is not set. Go to Space settings → Repository secrets → add HF_TOKEN."
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
MODEL_PATH = hf_hub_download(
|
| 80 |
+
repo_id=REPO_ID,
|
| 81 |
+
filename=MODEL_FILENAME,
|
| 82 |
+
token=HF_TOKEN,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
# 🧠 PrettyBird GGUF'i llama-cpp ile yükle
|
| 86 |
+
LLM = Llama(
|
| 87 |
+
model_path=MODEL_PATH,
|
| 88 |
+
n_ctx=4096,
|
| 89 |
+
n_threads=4, # CPU çekirdeğine göre artırabilirsin
|
| 90 |
+
# n_gpu_layers=0, # GPU Space'e geçersen burayı da oynarız
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def build_prompt(system_message: str, history, user_message: str) -> str:
|
| 95 |
+
parts = []
|
| 96 |
system_message = (system_message or "").strip()
|
| 97 |
if system_message:
|
| 98 |
+
parts.append(f"System: {system_message}")
|
| 99 |
|
|
|
|
| 100 |
for turn in history:
|
| 101 |
if isinstance(turn, (list, tuple)) and len(turn) == 2:
|
| 102 |
user_msg, assistant_msg = turn
|
| 103 |
if user_msg:
|
| 104 |
+
parts.append(f"User: {user_msg}")
|
| 105 |
if assistant_msg:
|
| 106 |
+
parts.append(f"Assistant: {assistant_msg}")
|
| 107 |
|
| 108 |
+
parts.append(f"User: {user_message}")
|
| 109 |
+
parts.append("Assistant:")
|
| 110 |
+
return "\n".join(parts)
|
| 111 |
|
| 112 |
|
| 113 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 114 |
+
prompt = build_prompt(system_message, history, message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
response = ""
|
| 117 |
+
stream = LLM(
|
| 118 |
+
prompt,
|
|
|
|
|
|
|
| 119 |
max_tokens=int(max_tokens),
|
| 120 |
temperature=float(temperature),
|
| 121 |
top_p=float(top_p),
|
| 122 |
+
stop=["User:", "System:"],
|
| 123 |
stream=True,
|
| 124 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
+
for chunk in stream:
|
| 127 |
+
# llama-cpp-python çıktısı: {"choices": [{"text": "..."}], ...}
|
| 128 |
+
token = chunk["choices"][0].get("text", "")
|
| 129 |
response += token
|
| 130 |
yield response
|
| 131 |
|
|
|
|
| 143 |
label="System message",
|
| 144 |
lines=6,
|
| 145 |
),
|
| 146 |
+
gr.Slider(1, 1024, value=512, step=1, label="Max new tokens"),
|
| 147 |
+
gr.Slider(0.1, 2.0, value=0.7, step=0.1, label="Temperature"),
|
| 148 |
+
gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
],
|
| 150 |
)
|
| 151 |
with gr.Column(scale=1):
|