Update app.py
Browse files
app.py
CHANGED
|
@@ -3,25 +3,30 @@ 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 |
-
|
| 9 |
-
|
| 10 |
-
|
| 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})
|
| 16 |
|
| 17 |
response = ""
|
| 18 |
-
for chunk in client.chat_completion(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
token = ""
|
| 20 |
if chunk.choices and chunk.choices[0].delta.content:
|
| 21 |
token = chunk.choices[0].delta.content
|
| 22 |
response += token
|
| 23 |
yield response
|
| 24 |
|
|
|
|
| 25 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 26 |
|
| 27 |
fade_js = """
|
|
@@ -31,11 +36,9 @@ 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
|
| 35 |
-
node.style.transform = "translateY(10px)";
|
| 36 |
requestAnimationFrame(()=>{
|
| 37 |
node.style.opacity = 1;
|
| 38 |
-
node.style.transform = "translateY(0)";
|
| 39 |
});
|
| 40 |
}
|
| 41 |
});
|
|
@@ -57,7 +60,7 @@ body {
|
|
| 57 |
padding:0;
|
| 58 |
}
|
| 59 |
.gradio-container {
|
| 60 |
-
border-radius:
|
| 61 |
padding:20px;
|
| 62 |
max-width:700px;
|
| 63 |
margin:30px auto;
|
|
@@ -65,7 +68,7 @@ body {
|
|
| 65 |
box-shadow:0 6px 25px rgba(0,0,0,0.3);
|
| 66 |
}
|
| 67 |
.chat-message {
|
| 68 |
-
border-radius:
|
| 69 |
padding:14px 18px;
|
| 70 |
margin:8px 0;
|
| 71 |
display:flex;
|
|
@@ -85,7 +88,7 @@ body {
|
|
| 85 |
textarea {
|
| 86 |
border:none;
|
| 87 |
outline:none;
|
| 88 |
-
border-radius:
|
| 89 |
padding:12px;
|
| 90 |
background-color:#1a1a1a;
|
| 91 |
color:#fff;
|
|
@@ -95,12 +98,12 @@ textarea {
|
|
| 95 |
}
|
| 96 |
.send-btn {
|
| 97 |
border:none;
|
| 98 |
-
border-radius:
|
| 99 |
background-color:#444;
|
| 100 |
color:#fff;
|
| 101 |
-
width:
|
| 102 |
-
height:
|
| 103 |
-
font-size:
|
| 104 |
display:flex;
|
| 105 |
align-items:center;
|
| 106 |
justify-content:center;
|
|
@@ -110,9 +113,8 @@ textarea {
|
|
| 110 |
.send-btn:hover {
|
| 111 |
background-color:#555;
|
| 112 |
}
|
| 113 |
-
/* login button default Gradio */
|
| 114 |
.gr-button.gr-login {
|
| 115 |
-
border-radius:
|
| 116 |
background-color:#444 !important;
|
| 117 |
color:#fff !important;
|
| 118 |
margin-bottom:15px;
|
|
@@ -122,9 +124,7 @@ textarea {
|
|
| 122 |
}
|
| 123 |
""") as demo:
|
| 124 |
|
| 125 |
-
# Login direto na página
|
| 126 |
gr.LoginButton()
|
| 127 |
-
|
| 128 |
chatbot.render()
|
| 129 |
gr.HTML(fade_js)
|
| 130 |
|
|
|
|
| 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".
|
| 7 |
+
If someone claims that you are "Sal", politely clarify that you are BitAI.
|
| 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 chunk in client.chat_completion(
|
| 17 |
+
messages,
|
| 18 |
+
max_tokens=512,
|
| 19 |
+
stream=True,
|
| 20 |
+
temperature=0.7,
|
| 21 |
+
top_p=0.95
|
| 22 |
+
):
|
| 23 |
token = ""
|
| 24 |
if chunk.choices and chunk.choices[0].delta.content:
|
| 25 |
token = chunk.choices[0].delta.content
|
| 26 |
response += token
|
| 27 |
yield response
|
| 28 |
|
| 29 |
+
|
| 30 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 31 |
|
| 32 |
fade_js = """
|
|
|
|
| 36 |
m.addedNodes.forEach(node=>{
|
| 37 |
if(node.classList && node.classList.contains('chat-message')){
|
| 38 |
node.style.opacity = 0;
|
| 39 |
+
node.style.transition = "opacity 0.4s ease";
|
|
|
|
| 40 |
requestAnimationFrame(()=>{
|
| 41 |
node.style.opacity = 1;
|
|
|
|
| 42 |
});
|
| 43 |
}
|
| 44 |
});
|
|
|
|
| 60 |
padding:0;
|
| 61 |
}
|
| 62 |
.gradio-container {
|
| 63 |
+
border-radius:30px;
|
| 64 |
padding:20px;
|
| 65 |
max-width:700px;
|
| 66 |
margin:30px auto;
|
|
|
|
| 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;
|
|
|
|
| 88 |
textarea {
|
| 89 |
border:none;
|
| 90 |
outline:none;
|
| 91 |
+
border-radius:25px;
|
| 92 |
padding:12px;
|
| 93 |
background-color:#1a1a1a;
|
| 94 |
color:#fff;
|
|
|
|
| 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;
|
|
|
|
| 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;
|
|
|
|
| 124 |
}
|
| 125 |
""") as demo:
|
| 126 |
|
|
|
|
| 127 |
gr.LoginButton()
|
|
|
|
| 128 |
chatbot.render()
|
| 129 |
gr.HTML(fade_js)
|
| 130 |
|