Salt40404 commited on
Commit
1ab8c25
·
verified ·
1 Parent(s): fb91cb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -39
app.py CHANGED
@@ -1,15 +1,15 @@
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".
8
  You always respond politely and helpfully. If a user requests something appropriate, fulfill it.
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 +22,8 @@ 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=>{
@@ -30,11 +31,11 @@ const observer = new MutationObserver(mutations=>{
30
  m.addedNodes.forEach(node=>{
31
  if(node.classList && node.classList.contains('chat-message')){
32
  node.style.opacity = 0;
33
- node.style.transform = 'translateY(10px)';
34
- node.style.transition = 'opacity 0.3s ease, transform 0.3s ease';
35
  requestAnimationFrame(()=>{
36
  node.style.opacity = 1;
37
- node.style.transform = 'translateY(0)';
38
  });
39
  }
40
  });
@@ -44,48 +45,87 @@ const observer = new MutationObserver(mutations=>{
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", ()=>{
62
- btn.style.transform = "scale(0.95)";
63
- setTimeout(()=> btn.style.transform="scale(1)",100);
64
- });
65
- }
66
  });
67
  </script>
68
  """
69
 
70
  with gr.Blocks(css="""
71
- body { background-color:#000; font-family:'Arial',sans-serif; margin:0; padding:0; }
72
- .gradio-container { border-radius:45px; padding:20px; max-width:700px; margin:30px auto; background-color:#121212; box-shadow:0 6px 25px rgba(0,0,0,0.3);}
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
+
7
  system_message = """You are BitAI (or Bit for short), a friendly chatbot created by the user "Sal".
8
  You always respond politely and helpfully. If a user requests something appropriate, fulfill it.
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
  response += token
23
  yield response
24
 
25
+ chatbot = gr.ChatInterface(respond, type="messages")
26
+
27
  fade_js = """
28
  <script>
29
  const observer = new MutationObserver(mutations=>{
 
31
  m.addedNodes.forEach(node=>{
32
  if(node.classList && node.classList.contains('chat-message')){
33
  node.style.opacity = 0;
34
+ node.style.transition = "opacity 0.4s ease, transform 0.4s ease";
35
+ node.style.transform = "translateY(10px)";
36
  requestAnimationFrame(()=>{
37
  node.style.opacity = 1;
38
+ node.style.transform = "translateY(0)";
39
  });
40
  }
41
  });
 
45
  document.addEventListener("DOMContentLoaded", ()=>{
46
  const chatContainer = document.querySelector(".chat-interface");
47
  if(chatContainer) observer.observe(chatContainer, {childList:true, subtree:true});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  });
49
  </script>
50
  """
51
 
52
  with gr.Blocks(css="""
53
+ body {
54
+ background-color:#000;
55
+ font-family:'Arial',sans-serif;
56
+ margin:0;
57
+ padding:0;
58
+ }
59
+ .gradio-container {
60
+ border-radius:45px;
61
+ padding:20px;
62
+ max-width:700px;
63
+ margin:30px auto;
64
+ background-color:#121212;
65
+ box-shadow:0 6px 25px rgba(0,0,0,0.3);
66
+ }
67
+ .chat-message {
68
+ border-radius:45px;
69
+ padding:14px 18px;
70
+ margin:8px 0;
71
+ display:flex;
72
+ flex-direction:column;
73
+ opacity:0;
74
+ }
75
+ .chat-message.user {
76
+ background-color:#1f1f1f;
77
+ color:#fff;
78
+ align-items:flex-end;
79
+ }
80
+ .chat-message.bot {
81
+ background-color:#2b2b2b;
82
+ color:#fff;
83
+ align-items:flex-start;
84
+ }
85
+ textarea {
86
+ border:none;
87
+ outline:none;
88
+ border-radius:45px;
89
+ padding:12px;
90
+ background-color:#1a1a1a;
91
+ color:#fff;
92
+ font-size:16px;
93
+ width:100%;
94
+ box-sizing:border-box;
95
+ }
96
+ .send-btn {
97
+ border:none;
98
+ border-radius:45px;
99
+ background-color:#444;
100
+ color:#fff;
101
+ width:48px;
102
+ height:48px;
103
+ font-size:18px;
104
+ display:flex;
105
+ align-items:center;
106
+ justify-content:center;
107
+ cursor:pointer;
108
+ margin-left:8px;
109
+ }
110
+ .send-btn:hover {
111
+ background-color:#555;
112
+ }
113
+ /* login button default Gradio */
114
+ .gr-button.gr-login {
115
+ border-radius:45px !important;
116
+ background-color:#444 !important;
117
+ color:#fff !important;
118
+ margin-bottom:15px;
119
+ }
120
+ .gr-button.gr-login:hover {
121
+ background-color:#555 !important;
122
+ }
123
  """) as demo:
124
 
125
  # Login direto na página
126
  gr.LoginButton()
127
+
128
+ chatbot.render()
 
129
  gr.HTML(fade_js)
130
 
131
  if __name__=="__main__":