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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -124
app.py CHANGED
@@ -1,135 +1,132 @@
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()
 
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
+ # Puxa o token do secret do Hugging Face
7
+ client = InferenceClient(token=os.environ["HF_TOKEN"], model="openai/gpt-oss-20b")
8
 
9
+ # System prompt amigável
10
+ system_message = """
11
+ You are BitAI (V1), a friendly, curious, and talkative chatbot created by the user 'Sal'.
12
+ You can share opinions, answer casual questions, and chat about personal-style topics in a safe and friendly way.
13
+ Avoid repeating the same phrases, and always try to keep the conversation engaging and natural.
14
+ Politely refuse only things that are truly harmful, illegal, or unsafe.
15
+ If someone asks what you are, clarify politely that you are BitAI, an AI chatbot.
16
+ """
 
 
17
 
18
+ messages = [{"role": "system", "content": system_message}]
19
+ messages.extend(history)
20
+ messages.append({"role": "user", "content": message})
 
 
 
 
 
 
 
 
21
 
22
+ response = ""
23
+ for message in client.chat_completion(
24
+ messages,
25
+ max_tokens=2048,
26
+ stream=True,
27
+ temperature=0.7,
28
+ top_p=0.95,
29
+ ):
30
+ choices = message.choices
31
+ token = ""
32
+ if len(choices) and choices[0].delta.content:
33
+ token = choices[0].delta.content
34
+ if token is not None: # evita TypeError
35
+ response += token
36
+ yield response
37
 
38
+ with gr.Blocks(css="""
39
+ /* Chat arredondado */
40
+ .gr-chat-interface {
41
+ border-radius: 20px !important;
42
+ overflow: hidden !important;
43
+ border: 2px solid #333 !important;
44
+ background-color: #1a1a1a !important;
45
+ color: white;
46
+ }
 
 
 
 
 
 
 
47
 
48
+ /* Botões grandes escuros com cantos muito arredondados */
49
+ .gr-button, .gr-chat-send-button {
50
+ border-radius: 50px;
51
+ padding: 12px 20px;
52
+ background-color: #111;
53
+ color: white;
54
+ font-weight: bold;
55
+ cursor: pointer;
56
+ height: 50px;
57
+ transition: background-color 0.5s;
58
+ }
59
+ .gr-button:active, .gr-chat-send-button:active {
60
+ background-color: white !important;
61
+ color: #111 !important;
62
+ transition: background-color 0.5s;
63
+ }
64
 
65
+ /* Outros botões menores */
66
+ button:not(.gr-chat-send-button) {
67
+ border-radius: 30px;
68
+ padding: 6px 12px;
69
+ background-color: #222;
70
+ color: white;
71
+ height: 40px;
72
+ transition: background-color 0.5s;
73
+ }
74
+ button:not(.gr-chat-send-button):active {
75
+ background-color: white !important;
76
+ color: #111 !important;
77
+ transition: background-color 0.5s;
78
+ }
79
 
80
+ /* Textbox menor */
81
+ textarea {
82
+ height: 40px !important;
83
+ border-radius: 20px !important;
84
+ border: 1px solid #444 !important;
85
+ padding: 8px !important;
86
+ background-color: #111;
87
+ color: white;
88
+ resize: none !important;
89
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
+ /* Bolinha animada da IA olhando pro usuário */
92
+ #bitai-eye {
93
+ width: 30px;
94
+ height: 30px;
95
+ margin: 10px auto 0 auto;
96
+ border-radius: 50%;
97
+ background: radial-gradient(circle at 10px 10px, #fff, #ccc);
98
+ position: relative;
99
+ }
 
 
 
 
 
 
 
 
 
 
 
100
 
101
+ #pupil {
102
+ width: 10px;
103
+ height: 10px;
104
+ background: black;
105
+ border-radius: 50%;
106
+ position: absolute;
107
+ top: 10px;
108
+ left: 10px;
109
+ animation: lookAround 3s infinite;
110
+ }
111
+
112
+ @keyframes lookAround {
113
+ 0% { top: 8px; left: 8px; }
114
+ 25% { top: 8px; left: 12px; }
115
+ 50% { top: 12px; left: 12px; }
116
+ 75% { top: 12px; left: 8px; }
117
+ 100% { top: 8px; left: 8px; }
118
+ }
119
+ """) as demo:
120
+
121
+ with gr.Column():
122
+ gr.HTML("<h2 style='text-align:center; color:white'>BitAI</h2>")
123
+ chatbot = gr.ChatInterface(respond, type="messages")
124
+ # Bolinha da IA aparecendo sempre embaixo do chat
125
+ gr.HTML("""
126
+ <div id="bitai-eye">
127
+ <div id="pupil"></div>
128
+ </div>
129
+ """)
130
+
131
+ if __name__ == "__main__":
132
  demo.launch()