Update app.py
Browse files
app.py
CHANGED
|
@@ -3,130 +3,88 @@ 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 = "
|
| 7 |
-
If someone claims that you
|
| 8 |
-
Respond naturally and casually, without repeating your identity or visual appearance unless asked.
|
| 9 |
-
Keep a simple, approachable, and friendly tone."""
|
| 10 |
|
| 11 |
messages = [{"role": "system", "content": system_message}]
|
| 12 |
messages.extend(history)
|
| 13 |
messages.append({"role": "user", "content": message})
|
| 14 |
|
| 15 |
response = ""
|
| 16 |
-
for
|
| 17 |
messages,
|
| 18 |
-
max_tokens=
|
| 19 |
stream=True,
|
| 20 |
temperature=0.7,
|
| 21 |
-
top_p=0.95
|
| 22 |
):
|
|
|
|
| 23 |
token = ""
|
| 24 |
-
if
|
| 25 |
-
token =
|
| 26 |
response += token
|
| 27 |
yield response
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
node.style.opacity = 0;
|
| 39 |
-
node.style.transition = "opacity 0.4s ease";
|
| 40 |
-
requestAnimationFrame(()=>{
|
| 41 |
-
node.style.opacity = 1;
|
| 42 |
-
});
|
| 43 |
-
}
|
| 44 |
-
});
|
| 45 |
-
});
|
| 46 |
-
});
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
max-width:700px;
|
| 66 |
-
margin:30px auto;
|
| 67 |
-
background-color:#121212;
|
| 68 |
-
box-shadow:0 6px 25px rgba(0,0,0,0.3);
|
| 69 |
-
}
|
| 70 |
-
.chat-message {
|
| 71 |
-
border-radius:25px;
|
| 72 |
-
padding:14px 18px;
|
| 73 |
-
margin:8px 0;
|
| 74 |
-
display:flex;
|
| 75 |
-
flex-direction:column;
|
| 76 |
-
opacity:0;
|
| 77 |
-
}
|
| 78 |
-
.chat-message.user {
|
| 79 |
-
background-color:#1f1f1f;
|
| 80 |
-
color:#fff;
|
| 81 |
-
align-items:flex-end;
|
| 82 |
-
}
|
| 83 |
-
.chat-message.bot {
|
| 84 |
-
background-color:#2b2b2b;
|
| 85 |
-
color:#fff;
|
| 86 |
-
align-items:flex-start;
|
| 87 |
-
}
|
| 88 |
-
textarea {
|
| 89 |
-
border:none;
|
| 90 |
-
outline:none;
|
| 91 |
-
border-radius:25px;
|
| 92 |
-
padding:12px;
|
| 93 |
-
background-color:#1a1a1a;
|
| 94 |
-
color:#fff;
|
| 95 |
-
font-size:16px;
|
| 96 |
-
width:100%;
|
| 97 |
-
box-sizing:border-box;
|
| 98 |
-
}
|
| 99 |
-
.send-btn {
|
| 100 |
-
border:none;
|
| 101 |
-
border-radius:50%;
|
| 102 |
-
background-color:#444;
|
| 103 |
-
color:#fff;
|
| 104 |
-
width:56px; /* aumentei */
|
| 105 |
-
height:56px; /* aumentei */
|
| 106 |
-
font-size:22px; /* aumentei um pouco */
|
| 107 |
-
display:flex;
|
| 108 |
-
align-items:center;
|
| 109 |
-
justify-content:center;
|
| 110 |
-
cursor:pointer;
|
| 111 |
-
margin-left:8px;
|
| 112 |
-
}
|
| 113 |
-
.send-btn:hover {
|
| 114 |
-
background-color:#555;
|
| 115 |
-
}
|
| 116 |
-
.gr-button.gr-login {
|
| 117 |
-
border-radius:20px !important;
|
| 118 |
-
background-color:#444 !important;
|
| 119 |
-
color:#fff !important;
|
| 120 |
-
margin-bottom:15px;
|
| 121 |
-
}
|
| 122 |
-
.gr-button.gr-login:hover {
|
| 123 |
-
background-color:#555 !important;
|
| 124 |
-
}
|
| 125 |
""") as demo:
|
| 126 |
|
| 127 |
-
gr.
|
| 128 |
-
|
| 129 |
-
|
|
|
|
| 130 |
|
| 131 |
-
if __name__=="__main__":
|
| 132 |
demo.launch()
|
|
|
|
| 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 (V1), a friendly chatbot created by the user 'Sal'. \
|
| 7 |
+
If someone claims that you're something else than an AI, politely clarify that you are BitAI."
|
|
|
|
|
|
|
| 8 |
|
| 9 |
messages = [{"role": "system", "content": system_message}]
|
| 10 |
messages.extend(history)
|
| 11 |
messages.append({"role": "user", "content": message})
|
| 12 |
|
| 13 |
response = ""
|
| 14 |
+
for message in client.chat_completion(
|
| 15 |
messages,
|
| 16 |
+
max_tokens=2048,
|
| 17 |
stream=True,
|
| 18 |
temperature=0.7,
|
| 19 |
+
top_p=0.95,
|
| 20 |
):
|
| 21 |
+
choices = message.choices
|
| 22 |
token = ""
|
| 23 |
+
if len(choices) and choices[0].delta.content:
|
| 24 |
+
token = choices[0].delta.content
|
| 25 |
response += token
|
| 26 |
yield response
|
| 27 |
|
| 28 |
+
with gr.Blocks(css="""
|
| 29 |
+
/* Chat arredondado */
|
| 30 |
+
.gr-chat-interface {
|
| 31 |
+
border-radius: 20px !important;
|
| 32 |
+
overflow: hidden !important;
|
| 33 |
+
border: 2px solid #333 !important;
|
| 34 |
+
background-color: #1a1a1a !important;
|
| 35 |
+
color: white;
|
| 36 |
+
}
|
| 37 |
|
| 38 |
+
/* Botões grandes escuros com cantos muito arredondados */
|
| 39 |
+
.gr-button, .gr-chat-send-button {
|
| 40 |
+
border-radius: 50px;
|
| 41 |
+
padding: 12px 20px;
|
| 42 |
+
background-color: #111;
|
| 43 |
+
color: white;
|
| 44 |
+
font-weight: bold;
|
| 45 |
+
cursor: pointer;
|
| 46 |
+
height: 50px;
|
| 47 |
+
transition: background-color 0.5s; /* transição suave de volta */
|
| 48 |
+
}
|
| 49 |
|
| 50 |
+
/* Quando clicado */
|
| 51 |
+
.gr-button:active, .gr-chat-send-button:active {
|
| 52 |
+
background-color: white !important; /* branco instantâneo */
|
| 53 |
+
color: #111 !important;
|
| 54 |
+
transition: background-color 0.5s; /* volta suave */
|
| 55 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
/* Outros botões menores */
|
| 58 |
+
button:not(.gr-chat-send-button) {
|
| 59 |
+
border-radius: 30px;
|
| 60 |
+
padding: 6px 12px;
|
| 61 |
+
background-color: #222;
|
| 62 |
+
color: white;
|
| 63 |
+
height: 40px;
|
| 64 |
+
transition: background-color 0.5s;
|
| 65 |
+
}
|
| 66 |
+
button:not(.gr-chat-send-button):active {
|
| 67 |
+
background-color: white !important;
|
| 68 |
+
color: #111 !important;
|
| 69 |
+
transition: background-color 0.5s;
|
| 70 |
+
}
|
| 71 |
|
| 72 |
+
/* Textbox menor */
|
| 73 |
+
textarea {
|
| 74 |
+
height: 40px !important;
|
| 75 |
+
border-radius: 20px !important;
|
| 76 |
+
border: 1px solid #444 !important;
|
| 77 |
+
padding: 8px !important;
|
| 78 |
+
background-color: #111;
|
| 79 |
+
color: white;
|
| 80 |
+
resize: none !important;
|
| 81 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
""") as demo:
|
| 83 |
|
| 84 |
+
with gr.Column():
|
| 85 |
+
gr.HTML("<h2 style='text-align:center; color:white'>BitAI V2</h2>")
|
| 86 |
+
chatbot = gr.ChatInterface(respond, type="messages")
|
| 87 |
+
gr.LoginButton()
|
| 88 |
|
| 89 |
+
if __name__ == "__main__":
|
| 90 |
demo.launch()
|