Salt40404 commited on
Commit
32c1903
·
verified ·
1 Parent(s): c13027d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -16
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Função principal que chama o modelo
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".
@@ -9,7 +8,7 @@ You always respond politely and helpfully. If a user requests something appropri
9
  If a user requests something harmful, illegal, or inappropriate, politely refuse.
10
  If a user keeps insisting on harmful requests, firmly tell them to stop and that they cannot use the service for that purpose.
11
  Keep a simple, approachable, and friendly tone otherwise."""
12
-
13
  messages = [{"role": "system", "content": system_message}]
14
  messages.extend(history)
15
  messages.append({"role": "user", "content": message})
@@ -22,7 +21,6 @@ Keep a simple, approachable, and friendly tone otherwise."""
22
  response += token
23
  yield response
24
 
25
- # JS para animações suaves
26
  fade_js = """
27
  <script>
28
  const observer = new MutationObserver(mutations=>{
@@ -40,22 +38,21 @@ const observer = new MutationObserver(mutations=>{
40
  });
41
  });
42
  });
43
-
44
  document.addEventListener("DOMContentLoaded", ()=>{
45
  const chatContainer = document.querySelector(".chat-interface");
46
  if(chatContainer) observer.observe(chatContainer, {childList:true, subtree:true});
47
 
48
- // Animação sutil ao digitar na textarea
49
  const txt = document.querySelector("textarea");
50
  if(txt){
 
51
  txt.addEventListener("input", ()=>{
52
- txt.style.transition = "background-color 0.15s ease";
53
- txt.style.backgroundColor = "#222";
54
- setTimeout(()=> txt.style.backgroundColor="#1a1a1a",150);
55
  });
56
  }
57
 
58
- // Clique no botão anima
59
  const btn = document.querySelector(".send-btn");
60
  if(btn){
61
  btn.addEventListener("click", ()=>{
@@ -73,19 +70,32 @@ body { background-color:#000; font-family:'Arial',sans-serif; margin:0; padding:
73
  .chat-message { border-radius:45px; padding:14px 18px; margin:8px 0; display:flex; flex-direction:column; opacity:0;}
74
  .chat-message.user { background-color:#1f1f1f; color:#fff; align-items:flex-end;}
75
  .chat-message.bot { background-color:#2b2b2b; color:#fff; align-items:flex-start;}
76
- textarea { border:none; outline:none; border-radius:45px; padding:12px; background-color:#1a1a1a; color:#fff; font-size:16px; flex:1; height:48px; box-sizing:border-box;}
77
- .send-btn { border:none; border-radius:45px; background-color:#444; color:#fff; width:48px; height:48px; font-size:18px; display:flex; align-items:center; justify-content:center; cursor:pointer; margin-left:8px; transition:transform 0.1s ease;}
78
- .send-btn:hover { background-color:#555;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  .gr-button.gr-login { border-radius:45px !important; background-color:#222 !important; color:#fff !important; margin-bottom:15px;}
80
  .gr-button.gr-login:hover { background-color:#444 !important;}
81
- .input-container { display:flex; margin-top:10px; }
82
  """) as demo:
83
 
84
- # Login direto na página
85
  gr.LoginButton()
86
-
87
  chatbot = gr.ChatInterface(respond, type="messages")
88
-
89
  gr.HTML(fade_js)
90
 
91
  if __name__=="__main__":
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
4
  def respond(message, history: list[dict[str, str]], hf_token: gr.OAuthToken):
5
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
6
  system_message = """You are BitAI (or Bit for short), a friendly chatbot created by the user "Sal".
 
8
  If a user requests something harmful, illegal, or inappropriate, politely refuse.
9
  If a user keeps insisting on harmful requests, firmly tell them to stop and that they cannot use the service for that purpose.
10
  Keep a simple, approachable, and friendly tone otherwise."""
11
+
12
  messages = [{"role": "system", "content": system_message}]
13
  messages.extend(history)
14
  messages.append({"role": "user", "content": message})
 
21
  response += token
22
  yield response
23
 
 
24
  fade_js = """
25
  <script>
26
  const observer = new MutationObserver(mutations=>{
 
38
  });
39
  });
40
  });
 
41
  document.addEventListener("DOMContentLoaded", ()=>{
42
  const chatContainer = document.querySelector(".chat-interface");
43
  if(chatContainer) observer.observe(chatContainer, {childList:true, subtree:true});
44
 
45
+ // auto resize do textarea
46
  const txt = document.querySelector("textarea");
47
  if(txt){
48
+ txt.style.transition = "height 0.2s ease";
49
  txt.addEventListener("input", ()=>{
50
+ txt.style.height = "auto";
51
+ txt.style.height = (txt.scrollHeight) + "px";
 
52
  });
53
  }
54
 
55
+ // animação de clique do botão
56
  const btn = document.querySelector(".send-btn");
57
  if(btn){
58
  btn.addEventListener("click", ()=>{
 
70
  .chat-message { border-radius:45px; padding:14px 18px; margin:8px 0; display:flex; flex-direction:column; opacity:0;}
71
  .chat-message.user { background-color:#1f1f1f; color:#fff; align-items:flex-end;}
72
  .chat-message.bot { background-color:#2b2b2b; color:#fff; align-items:flex-start;}
73
+
74
+ /* input com botão dentro */
75
+ .input-container {
76
+ display:flex;
77
+ position:relative;
78
+ margin-top:10px;
79
+ }
80
+ textarea {
81
+ border:none; outline:none; border-radius:45px; padding:12px 60px 12px 12px;
82
+ background-color:#1a1a1a; color:#fff; font-size:16px; flex:1;
83
+ min-height:48px; max-height:200px; box-sizing:border-box;
84
+ overflow:hidden; resize:none; transition:height 0.2s ease;
85
+ }
86
+ .send-btn {
87
+ position:absolute; right:4px; top:50%; transform:translateY(-50%);
88
+ border:none; border-radius:45px; background-color:#444; color:#fff;
89
+ width:48px; height:48px; font-size:18px; display:flex;
90
+ align-items:center; justify-content:center; cursor:pointer; transition:transform 0.1s ease;
91
+ }
92
+ .send-btn:hover { background-color:#555; }
93
  .gr-button.gr-login { border-radius:45px !important; background-color:#222 !important; color:#fff !important; margin-bottom:15px;}
94
  .gr-button.gr-login:hover { background-color:#444 !important;}
 
95
  """) as demo:
96
 
 
97
  gr.LoginButton()
 
98
  chatbot = gr.ChatInterface(respond, type="messages")
 
99
  gr.HTML(fade_js)
100
 
101
  if __name__=="__main__":