Salt40404 commited on
Commit
9373afa
·
verified ·
1 Parent(s): 18dda04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -29
app.py CHANGED
@@ -1,43 +1,135 @@
1
  import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
- import time
5
 
6
- def respond(message, history):
7
  client = InferenceClient(token=os.environ["HF_TOKEN"], model="openai/gpt-oss-20b")
8
-
9
- system_message = "You are BitAI (V1), a friendly chatbot..."
10
- messages = [{"role":"system","content":system_message}]
 
 
 
 
 
 
11
  messages.extend(history)
12
- messages.append({"role":"user","content":message})
13
-
14
- yield "⏳ BitAI is typing..." # aqui mostra o loader
15
-
16
- # Simulando streaming real
17
  response = ""
18
- for m in client.chat_completion(messages, stream=True):
19
- token = m.choices[0].delta.content if m.choices else ""
 
 
 
 
 
 
20
  response += token
21
  yield response
22
 
23
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  with gr.Column():
25
  gr.HTML("<h2 style='text-align:center; color:white'>BitAI</h2>")
26
  chatbot = gr.ChatInterface(respond, type="messages")
27
-
28
- # Loader fora do chat
29
- loader = gr.HTML("<div style='text-align:center; margin-top:10px;'>"
30
- "<div style='width:20px; height:20px; border-radius:50%; "
31
- "background:linear-gradient(45deg,#ff6,#f06); animation:moveLoader 1s infinite alternate;'></div>"
32
- "</div>")
33
- demo.load(lambda: None, [], loader) # placeholder pra ativar animação
34
-
35
- css_loader = """
36
- @keyframes moveLoader {
37
- 0% { transform: translateY(0px); }
38
- 50% { transform: translateY(5px); }
39
- 100% { transform: translateY(0px); }
40
- }
41
- """
 
 
42
 
43
- demo.launch()
 
 
1
  import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
 
4
 
5
+ def respond(message, history: list[dict[str, str]]):
6
  client = InferenceClient(token=os.environ["HF_TOKEN"], model="openai/gpt-oss-20b")
7
+
8
+ system_message = """
9
+ You are BitAI (V1), a friendly, curious, and talkative chatbot created by the user 'Sal'.
10
+ You can share opinions, answer casual questions, and chat about personal-style topics in a safe and friendly way.
11
+ Avoid repeating the same phrases, and always try to keep the conversation engaging and natural.
12
+ Politely refuse only things that are truly harmful, illegal, or unsafe.
13
+ If someone asks what you are, clarify politely that you are BitAI, an AI chatbot.
14
+ """
15
+ messages = [{"role": "system", "content": system_message}]
16
  messages.extend(history)
17
+ messages.append({"role": "user", "content": message})
18
+
 
 
 
19
  response = ""
20
+ for message in client.chat_completion(
21
+ messages,
22
+ max_tokens=2048,
23
+ stream=True,
24
+ temperature=0.7,
25
+ top_p=0.95,
26
+ ):
27
+ token = message.choices[0].delta.content if message.choices else ""
28
  response += token
29
  yield response
30
 
31
+ with gr.Blocks(css="""
32
+ /* Chat arredondado */
33
+ .gr-chat-interface {
34
+ border-radius: 20px !important;
35
+ overflow: hidden !important;
36
+ border: 2px solid #333 !important;
37
+ background-color: #1a1a1a !important;
38
+ color: white;
39
+ }
40
+
41
+ /* Botões grandes escuros com cantos muito arredondados */
42
+ .gr-button, .gr-chat-send-button {
43
+ border-radius: 50px;
44
+ padding: 12px 20px;
45
+ background-color: #111;
46
+ color: white;
47
+ font-weight: bold;
48
+ cursor: pointer;
49
+ height: 50px;
50
+ transition: background-color 0.5s;
51
+ }
52
+ .gr-button:active, .gr-chat-send-button:active {
53
+ background-color: white !important;
54
+ color: #111 !important;
55
+ transition: background-color 0.5s;
56
+ }
57
+
58
+ /* Outros botões menores */
59
+ button:not(.gr-chat-send-button) {
60
+ border-radius: 30px;
61
+ padding: 6px 12px;
62
+ background-color: #222;
63
+ color: white;
64
+ height: 40px;
65
+ transition: background-color 0.5s;
66
+ }
67
+ button:not(.gr-chat-send-button):active {
68
+ background-color: white !important;
69
+ color: #111 !important;
70
+ transition: background-color 0.5s;
71
+ }
72
+
73
+ /* Textbox menor */
74
+ textarea {
75
+ height: 40px !important;
76
+ border-radius: 20px !important;
77
+ border: 1px solid #444 !important;
78
+ padding: 8px !important;
79
+ background-color: #111;
80
+ color: white;
81
+ resize: none !important;
82
+ }
83
+
84
+ /* Bolinha “olhando” da IA */
85
+ #bitai-eye {
86
+ width: 30px;
87
+ height: 30px;
88
+ margin: 10px auto 0 auto;
89
+ border-radius: 50%;
90
+ background: radial-gradient(circle at 10px 10px, #fff, #ccc);
91
+ position: relative;
92
+ display: none; /* começa escondida */
93
+ }
94
+ #pupil {
95
+ width: 10px;
96
+ height: 10px;
97
+ background: black;
98
+ border-radius: 50%;
99
+ position: absolute;
100
+ top: 10px;
101
+ left: 10px;
102
+ animation: lookAround 3s infinite;
103
+ }
104
+ @keyframes lookAround {
105
+ 0% { top: 8px; left: 8px; }
106
+ 25% { top: 8px; left: 12px; }
107
+ 50% { top: 12px; left: 12px; }
108
+ 75% { top: 12px; left: 8px; }
109
+ 100% { top: 8px; left: 8px; }
110
+ }
111
+ """) as demo:
112
+
113
  with gr.Column():
114
  gr.HTML("<h2 style='text-align:center; color:white'>BitAI</h2>")
115
  chatbot = gr.ChatInterface(respond, type="messages")
116
+ # Bolinha animada
117
+ eye = gr.HTML("""
118
+ <div id="bitai-eye">
119
+ <div id="pupil"></div>
120
+ </div>
121
+ <script>
122
+ // Mostrar a bolinha depois que a IA termina de digitar
123
+ const observer = new MutationObserver(() => {
124
+ const messages = document.querySelectorAll('.gr-chat-message');
125
+ const lastMsg = messages[messages.length-1];
126
+ if(lastMsg && lastMsg.classList.contains('gr-chat-message-assistant')){
127
+ document.getElementById('bitai-eye').style.display = 'block';
128
+ }
129
+ });
130
+ observer.observe(document.querySelector('.gr-chat-interface'), {childList: true});
131
+ </script>
132
+ """)
133
 
134
+ if __name__ == "__main__":
135
+ demo.launch()