Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 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 |
|
|
@@ -28,70 +29,64 @@ Keep a simple, approachable, and friendly tone."""
|
|
| 28 |
response += token
|
| 29 |
yield response
|
| 30 |
|
|
|
|
| 31 |
bit_icon_html = """
|
| 32 |
-
<
|
| 33 |
-
|
| 34 |
-
<
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
<circle class="dot extra-dot" cx="80" cy="78" r="8"/>
|
| 39 |
-
</svg>
|
| 40 |
-
</div>
|
| 41 |
-
</div>
|
| 42 |
|
| 43 |
<script>
|
| 44 |
-
function
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
if(!chatContainer) return setTimeout(initBitAI, 500);
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
});
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
observer.observe(chatContainer, { childList: true, subtree: true });
|
| 63 |
}
|
| 64 |
-
|
| 65 |
-
// Inicia observador após o DOM carregar
|
| 66 |
-
document.addEventListener('DOMContentLoaded', initBitAI);
|
| 67 |
-
initBitAI();
|
| 68 |
</script>
|
| 69 |
|
| 70 |
<style>
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
@keyframes wave { 0%,100%{ transform:translateY(0); } 50%{ transform:translateY(-12%); } }
|
| 84 |
</style>
|
| 85 |
"""
|
| 86 |
|
| 87 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 88 |
|
| 89 |
with gr.Blocks(css="""
|
| 90 |
-
body { background-color: #
|
| 91 |
-
.gradio-container { border-radius:
|
| 92 |
-
.chat-message { border-radius:
|
| 93 |
.chat-message.user { background-color: #dceefc; }
|
| 94 |
-
.chat-message.bot { background-color: #
|
| 95 |
""") as demo:
|
| 96 |
with gr.Sidebar():
|
| 97 |
gr.LoginButton()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Função principal da IA
|
| 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 |
|
|
|
|
| 29 |
response += token
|
| 30 |
yield response
|
| 31 |
|
| 32 |
+
# HTML do ícone da BitAI
|
| 33 |
bit_icon_html = """
|
| 34 |
+
<svg class="bit-icon" viewBox="0 0 160 160">
|
| 35 |
+
<circle class="face" cx="80" cy="80" r="72"/>
|
| 36 |
+
<circle class="dot eye-left"/>
|
| 37 |
+
<circle class="dot eye-right"/>
|
| 38 |
+
<circle class="dot extra-dot" cx="80" cy="78" r="8"/>
|
| 39 |
+
</svg>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
<script>
|
| 42 |
+
function animateEyes(node){
|
| 43 |
+
const wrap = node.querySelector('.bit-icon');
|
| 44 |
+
wrap.classList.add('thinking');
|
| 45 |
+
setTimeout(()=> wrap.classList.remove('thinking'), 1200);
|
| 46 |
+
}
|
|
|
|
| 47 |
|
| 48 |
+
// Observa novas mensagens do bot
|
| 49 |
+
const chatContainer = document.querySelector('.chat-interface');
|
| 50 |
+
if(chatContainer){
|
| 51 |
+
const observer = new MutationObserver(mutations => {
|
| 52 |
+
mutations.forEach(m => {
|
| 53 |
+
m.addedNodes.forEach(node => {
|
| 54 |
+
if(node.classList && node.classList.contains('bot')){
|
| 55 |
+
animateEyes(node);
|
| 56 |
+
// move o ícone para o topo da mensagem
|
| 57 |
+
node.insertAdjacentElement('afterbegin', wrap.cloneNode(true));
|
| 58 |
+
}
|
| 59 |
+
});
|
| 60 |
+
});
|
| 61 |
});
|
| 62 |
+
observer.observe(chatContainer, {childList:true, subtree:true});
|
|
|
|
|
|
|
| 63 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
</script>
|
| 65 |
|
| 66 |
<style>
|
| 67 |
+
.bit-icon{ width:30px; height:30px; margin-right:5px; vertical-align:middle;}
|
| 68 |
+
.face{ fill:#0b1020; }
|
| 69 |
+
.dot{ fill:#fff; transition: all 500ms ease; }
|
| 70 |
+
.eye-left { cx:56; cy:62; r:10;}
|
| 71 |
+
.eye-right{ cx:104; cy:62; r:10;}
|
| 72 |
+
.extra-dot{ opacity:0; transform:translateY(10%); transition: all 500ms ease;}
|
| 73 |
+
.wrap.thinking .extra-dot{ opacity:1; transform:translateY(0);}
|
| 74 |
+
.wrap.thinking .dot{ animation: wave 1.4s infinite ease-in-out;}
|
| 75 |
+
.wrap.thinking .eye-left { animation-delay:0s; }
|
| 76 |
+
.wrap.thinking .extra-dot{ animation-delay:0.25s;}
|
| 77 |
+
.wrap.thinking .eye-right{ animation-delay:0.5s;}
|
| 78 |
+
@keyframes wave{0%,100%{transform:translateY(0);}50%{transform:translateY(-12%);}}
|
|
|
|
| 79 |
</style>
|
| 80 |
"""
|
| 81 |
|
| 82 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 83 |
|
| 84 |
with gr.Blocks(css="""
|
| 85 |
+
body { background-color: #000; font-family: 'Arial', sans-serif; }
|
| 86 |
+
.gradio-container { border-radius: 20px; padding: 15px; max-width:700px; margin:20px auto; background-color:#fff; }
|
| 87 |
+
.chat-message { border-radius: 15px; padding:10px 15px; margin:5px 0; display:flex; align-items:flex-start;}
|
| 88 |
.chat-message.user { background-color: #dceefc; }
|
| 89 |
+
.chat-message.bot { background-color: #f0f0f0; justify-content:flex-start; }
|
| 90 |
""") as demo:
|
| 91 |
with gr.Sidebar():
|
| 92 |
gr.LoginButton()
|