Salt40404 commited on
Commit
ece3423
·
verified ·
1 Parent(s): abda3c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -29
app.py CHANGED
@@ -4,16 +4,28 @@ from huggingface_hub import InferenceClient
4
  # Função do bot
5
  def respond(message, history: list[dict[str, str]], hf_token: gr.OAuthToken):
6
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
7
- system_message = """You are BitAI (or Bit for short), a friendly chatbot created by the user "Sal".
8
- You respond politely, refuse inappropriate requests, and keep a friendly tone."""
9
-
 
 
 
 
 
 
10
  messages = [{"role": "system", "content": system_message}]
11
  messages.extend(history)
12
  messages.append({"role": "user", "content": message})
13
 
14
  response = ""
15
- for chunk in client.chat_completion(messages, max_tokens=512, stream=True, temperature=0.7, top_p=0.95):
16
- token = chunk.choices[0].delta.content if chunk.choices and chunk.choices[0].delta.content else ""
 
 
 
 
 
 
17
  response += token
18
  yield response
19
 
@@ -28,7 +40,7 @@ function initTitle() {
28
  titleContainer.innerHTML = `
29
  <div class="title-inner">
30
  <h1 class="chat-title">Talk with BitAI (W.I.P)</h1>
31
- <p class="chat-subtitle">Still updating, might not know everything, filter slightly broken</p>
32
  <button class="close-title-btn">
33
  <svg width="28" height="28" viewBox="0 0 24 24">
34
  <path fill="#fff" d="M12 16l-6-6h12z"/>
@@ -38,13 +50,13 @@ function initTitle() {
38
  `;
39
  grContainer.insertBefore(titleContainer, grContainer.firstChild);
40
 
41
- // animação de aparecer
42
  setTimeout(() => {
43
  titleContainer.style.opacity = "1";
44
  titleContainer.style.transform = "translateY(0)";
45
  }, 100);
46
 
47
- // fechar com a seta
48
  const closeBtn = titleContainer.querySelector(".close-title-btn");
49
  closeBtn.addEventListener("click", () => {
50
  titleContainer.style.transition = "all 0.4s ease";
@@ -55,23 +67,23 @@ function initTitle() {
55
  }
56
  }
57
 
58
- // esperar carregar tudo
59
  window.addEventListener("load", () => {
60
  setTimeout(initTitle, 300);
61
- });
62
 
63
- // deixar botão de enviar grande
64
- window.addEventListener("load", () => {
65
- const txtArea = document.querySelector("textarea");
66
- const btn = document.querySelector(".send-btn");
67
- if(txtArea && btn){
68
- const resize = () => {
69
  btn.style.height = txtArea.offsetHeight + "px";
70
  btn.style.width = txtArea.offsetHeight + "px";
71
- };
72
- resize();
73
- new ResizeObserver(resize).observe(txtArea);
74
- }
 
 
75
  });
76
  </script>
77
 
@@ -85,7 +97,7 @@ window.addEventListener("load", () => {
85
  position:relative;
86
  }
87
  .title-inner { display:inline-block; position:relative; }
88
- .chat-title { font-size:32px; color:#fff; margin-bottom:10px; cursor:pointer; }
89
  .chat-subtitle { font-size:14px; color:#aaa; margin-bottom:10px; }
90
  .close-title-btn {
91
  position:absolute;
@@ -97,14 +109,6 @@ window.addEventListener("load", () => {
97
  transition: transform 0.2s;
98
  }
99
  .close-title-btn:hover { transform:scale(1.2); }
100
- .send-btn {
101
- border:none;
102
- border-radius:50%;
103
- background:linear-gradient(145deg,#555,#444);
104
- color:#fff;
105
- cursor:pointer;
106
- transition:0.3s;
107
- }
108
  </style>
109
  """
110
 
 
4
  # Função do bot
5
  def respond(message, history: list[dict[str, str]], hf_token: gr.OAuthToken):
6
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
7
+
8
+ # Descrição melhorada
9
+ system_message = """You are BitAI (or simply Bit), a friendly chatbot created by the user "Sal".
10
+ - Always answer in a polite and clear way.
11
+ - Keep a playful and friendly personality, but never rude.
12
+ - Refuse harmful, inappropriate or unsafe requests.
13
+ - You are still a work in progress, so if you don’t know something, admit it kindly.
14
+ - Never claim to be "Sal". Only identify yourself as BitAI (Bit)."""
15
+
16
  messages = [{"role": "system", "content": system_message}]
17
  messages.extend(history)
18
  messages.append({"role": "user", "content": message})
19
 
20
  response = ""
21
+ for chunk in client.chat_completion(
22
+ messages, max_tokens=512, stream=True, temperature=0.7, top_p=0.95
23
+ ):
24
+ token = (
25
+ chunk.choices[0].delta.content
26
+ if chunk.choices and chunk.choices[0].delta.content
27
+ else ""
28
+ )
29
  response += token
30
  yield response
31
 
 
40
  titleContainer.innerHTML = `
41
  <div class="title-inner">
42
  <h1 class="chat-title">Talk with BitAI (W.I.P)</h1>
43
+ <p class="chat-subtitle">Your friendly AI, still learning answers might be limited</p>
44
  <button class="close-title-btn">
45
  <svg width="28" height="28" viewBox="0 0 24 24">
46
  <path fill="#fff" d="M12 16l-6-6h12z"/>
 
50
  `;
51
  grContainer.insertBefore(titleContainer, grContainer.firstChild);
52
 
53
+ // animação aparecer
54
  setTimeout(() => {
55
  titleContainer.style.opacity = "1";
56
  titleContainer.style.transform = "translateY(0)";
57
  }, 100);
58
 
59
+ // fechar com seta
60
  const closeBtn = titleContainer.querySelector(".close-title-btn");
61
  closeBtn.addEventListener("click", () => {
62
  titleContainer.style.transition = "all 0.4s ease";
 
67
  }
68
  }
69
 
70
+ // esperar carregar
71
  window.addEventListener("load", () => {
72
  setTimeout(initTitle, 300);
 
73
 
74
+ // deixar botão enviar grande
75
+ const observer = new MutationObserver(() => {
76
+ const txtArea = document.querySelector("textarea");
77
+ const btn = document.querySelector("button.primary");
78
+ if(txtArea && btn){
 
79
  btn.style.height = txtArea.offsetHeight + "px";
80
  btn.style.width = txtArea.offsetHeight + "px";
81
+ btn.style.borderRadius = "50%";
82
+ btn.style.fontSize = "16px";
83
+ observer.disconnect();
84
+ }
85
+ });
86
+ observer.observe(document.body, { childList: true, subtree: true });
87
  });
88
  </script>
89
 
 
97
  position:relative;
98
  }
99
  .title-inner { display:inline-block; position:relative; }
100
+ .chat-title { font-size:32px; color:#fff; margin-bottom:10px; }
101
  .chat-subtitle { font-size:14px; color:#aaa; margin-bottom:10px; }
102
  .close-title-btn {
103
  position:absolute;
 
109
  transition: transform 0.2s;
110
  }
111
  .close-title-btn:hover { transform:scale(1.2); }
 
 
 
 
 
 
 
 
112
  </style>
113
  """
114