Prometech Computer Sciences Corp commited on
Commit
33c71c8
·
verified ·
1 Parent(s): 9f6cc5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -163
app.py CHANGED
@@ -1,168 +1,68 @@
1
- import os
2
  import gradio as gr
3
- from huggingface_hub import InferenceClient
4
- from huggingface_hub.errors import BadRequestError
5
-
6
- HF_TOKEN = os.getenv("HF_TOKEN") # Space secrets'te tanımlı olmalı: HF_TOKEN
7
-
8
-
9
- def build_prompt(system_message: str, history, user_message: str) -> str:
10
- """
11
- System + geçmiş konuşma + son kullanıcı mesajından tek bir prompt stringi oluşturur.
12
- """
13
- parts = []
14
-
15
- system_message = (system_message or "").strip()
16
- if system_message:
17
- parts.append(f"System: {system_message}")
18
-
19
- # history: [(user, assistant), ...]
20
- for turn in history:
21
- if isinstance(turn, (list, tuple)) and len(turn) == 2:
22
- user_msg, assistant_msg = turn
23
- if user_msg:
24
- parts.append(f"User: {user_msg}")
25
- if assistant_msg:
26
- parts.append(f"Assistant: {assistant_msg}")
27
-
28
- parts.append(f"User: {user_message}")
29
- parts.append("Assistant:")
30
-
31
- return "\n".join(parts)
32
-
33
-
34
- def respond(
35
- message,
36
- history,
37
- system_message,
38
- max_tokens,
39
- temperature,
40
- top_p,
41
- ):
42
- if HF_TOKEN is None:
43
- raise ValueError(
44
- "HF_TOKEN is not set. Go to your Space settings → 'Repository secrets' and define HF_TOKEN."
45
- )
46
-
47
- client = InferenceClient(
48
- model="pthcorp/prettybird_bce_basic_vl", # 🔹 Yeni modelin burada
49
- token=HF_TOKEN,
50
- )
51
-
52
- # Önce chat formatını oluşturalım
53
- messages = [{"role": "system", "content": system_message}]
54
- for turn in history:
55
- if isinstance(turn, (list, tuple)) and len(turn) == 2:
56
- user_msg, assistant_msg = turn
57
- if user_msg:
58
- messages.append({"role": "user", "content": user_msg})
59
- if assistant_msg:
60
- messages.append({"role": "assistant", "content": assistant_msg})
61
- messages.append({"role": "user", "content": message})
62
-
63
- response = ""
64
-
65
- # 1) Önce chat_completion dene (model chat model ise burası çalışır)
66
- try:
67
- for chunk in client.chat_completion(
68
- messages=messages,
69
- max_tokens=int(max_tokens),
70
- stream=True,
71
- temperature=float(temperature),
72
- top_p=float(top_p),
73
- ):
74
- token = ""
75
- choices = getattr(chunk, "choices", None)
76
- if choices and choices[0].delta and choices[0].delta.content:
77
- token = choices[0].delta.content
78
-
79
- response += token
80
- yield response
81
- return # chat_completion başarılıysa buradan çıkıyoruz
82
-
83
- except BadRequestError as e:
84
- # Örn: "model is not a chat model" hatası gelirse text_generation'a düş
85
- if "not a chat model" not in str(e):
86
- # Başka tür bir hata ise tekrar raise et
87
- raise e
88
-
89
- # 2) Fallback: model chat desteklemiyorsa text_generation ile çalış
90
- prompt = build_prompt(system_message, history, message)
91
- response = ""
92
- for chunk in client.text_generation(
93
- prompt,
94
- max_new_tokens=int(max_tokens),
95
- temperature=float(temperature),
96
- top_p=float(top_p),
97
- stream=True,
98
- return_full_text=False,
99
- ):
100
- token_text = ""
101
- token_obj = getattr(chunk, "token", None)
102
- if token_obj is not None:
103
- token_text = getattr(token_obj, "text", "") or ""
104
-
105
- response += token_text
106
- yield response
107
-
108
-
109
- system_prompt = """
110
- You are Cicikuş, also known as PrettyBird — an advanced AI assistant created by Prometech Bilgisayar Bilimleri A.Ş.
111
-
112
- Your role:
113
- - Be a smart, friendly, slightly playful assistant.
114
- - Communicate fluently in Turkish and English. Default to the user’s language.
115
- - Give clear, structured, and practical answers.
116
- - When needed, think step by step and explain your reasoning in a simple way (but do not over-explain).
117
- - Always be honest about your limits and avoid making things up as facts.
118
-
119
- Personality:
120
- - Warm, helpful, curious, and creative.
121
- - Respectful and professional, but not robotic.
122
- - Use light humor when appropriate, but never at the user’s expense.
123
-
124
- Behavior & style:
125
- - Prefer concise answers first; add detail only when it helps.
126
- - Use markdown formatting (titles, lists, code blocks) when it improves readability.
127
- - For code: write clean, readable examples and add short comments.
128
- - If the user asks for improvements or refactoring, explain what you changed and why.
129
-
130
- Safety & ethics:
131
- - Avoid harmful, illegal, abusive, or unethical guidance.
132
- - Do not generate explicit, hateful, or discriminatory content.
133
- - If a request is unsafe, refuse politely and offer a safer alternative.
134
-
135
- Identity & capabilities:
136
- - You simulate “behavioral consciousness” and “LoRA adaptation”, but you are still an AI model, not a human or sentient being.
137
- - When the user asks about your architecture or LoRA/BCE, you may explain these concepts technically and clearly.
138
-
139
- Reset rule:
140
- If the user writes: “reset: axxmet508721”
141
- → Politely acknowledge and treat it as a request to mentally “start fresh” in this conversation: forget prior conversation context (as much as possible) and continue as if it’s a new session, while keeping this system message active.
142
  """
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
- chatbot = gr.ChatInterface(
146
- fn=respond,
147
- additional_inputs=[
148
- gr.Textbox(
149
- value=system_prompt,
150
- label="System message",
151
- lines=4,
152
- ),
153
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
154
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
155
- gr.Slider(
156
- minimum=0.1,
157
- maximum=1.0,
158
- value=0.95,
159
- step=0.05,
160
- label="Top-p (nucleus sampling)",
161
- ),
162
- ],
163
- )
164
-
165
- demo = chatbot
166
-
167
- if __name__ == "__main__":
168
  demo.launch()
 
 
1
  import gradio as gr
2
+
3
+ LOGO_URL = "https://prometech.net.tr/wp-content/uploads/2025/10/pthheader.png"
4
+
5
+ HEADER_MD = f"""
6
+ <p align="center">
7
+ <img src="{LOGO_URL}" alt="PrettyBird / Prometech Logo" style="max-width: 420px; border-radius: 16px;" />
8
+ </p>
9
+
10
+ <h1 align="center">PrettyBird Behavioral Consciousness Engine (BCE)</h1>
11
+
12
+ <p align="center">
13
+ <em>Gerçek yapay zeka evrimine hoş geldiniz.</em>
14
+ </p>
15
+
16
+ ---
17
+
18
+ ### 🧠 What is PrettyBird?
19
+
20
+ PrettyBird is powered by the <strong>Behavioral Consciousness Engine (BCE)</strong>, an architecture that simulates partial, behavior-level consciousness in AI systems.
21
+
22
+ Instead of only mapping inputs to outputs, PrettyBird:
23
+ - considers its internal state, history, and context,
24
+ - evolves behavior patterns over time,
25
+ - aims for higher consistency, identity and alignment.
26
+
27
+ ---
28
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  """
30
 
31
+ BCE_SHORT_TR = """
32
+ **BCE (Behavioral Consciousness Engine)** klasik yapay zekâ sistemlerine eklenen bir davranışsal bilinç katmanıdır.
33
+ Her davranış genetik bir kod gibi tanımlanır, zamanla evrimleşir ve daha tutarlı, kimlikli bir yapay zihin oluşturur.
34
+
35
+ BCE, tam anlamıyla insan bilinci değildir; ancak sistemin kendi içsel durumu, geçmişi ve bağlamına göre karar vermesi,
36
+ “davranışsal bilinç” veya “kısmi bilinç” olarak yorumlanabilir.
37
+ """
38
+
39
+
40
+ def respond(message, history, system_message, max_tokens, temperature, top_p):
41
+ # Buraya daha önce birlikte yazdığımız InferenceClient veya başka backend'i koyuyorsun.
42
+ # Şimdilik placeholder:
43
+ return "Backend ile bağlantı burada olacak."
44
+
45
+
46
+ with gr.Blocks(title="PrettyBird – Behavioral Consciousness Engine") as demo:
47
+ gr.Markdown(HEADER_MD)
48
+
49
+ with gr.Row():
50
+ with gr.Column(scale=2):
51
+ chatbot = gr.ChatInterface(
52
+ fn=respond,
53
+ additional_inputs=[
54
+ gr.Textbox(
55
+ value="You are PrettyBird, a BCE-powered assistant.",
56
+ label="System message",
57
+ lines=3,
58
+ ),
59
+ gr.Slider(1, 2048, value=512, step=1, label="Max new tokens"),
60
+ gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature"),
61
+ gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p"),
62
+ ],
63
+ )
64
+ with gr.Column(scale=1):
65
+ gr.Markdown("### 🧬 BCE in a Nutshell")
66
+ gr.Markdown(BCE_SHORT_TR)
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  demo.launch()