Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 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")
|
|
@@ -18,82 +19,11 @@ Keep a simple, approachable, and friendly tone."""
|
|
| 18 |
if chunk.choices and chunk.choices[0].delta.content:
|
| 19 |
token = chunk.choices[0].delta.content
|
| 20 |
response += token
|
| 21 |
-
yield response
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
<circle class="dot eye-left"/>
|
| 28 |
-
<circle class="dot eye-right"/>
|
| 29 |
-
<circle class="dot extra-dot" cx="80" cy="78" r="8"/>
|
| 30 |
-
</svg>
|
| 31 |
-
|
| 32 |
-
<script>
|
| 33 |
-
function addBitIconToBotMessages(){
|
| 34 |
-
const chatContainer = document.querySelector('.chat-interface');
|
| 35 |
-
if(!chatContainer) return setTimeout(addBitIconToBotMessages,500);
|
| 36 |
-
|
| 37 |
-
const observer = new MutationObserver(mutations=>{
|
| 38 |
-
mutations.forEach(m=>{
|
| 39 |
-
m.addedNodes.forEach(node=>{
|
| 40 |
-
if(node.classList && node.classList.contains('bot') && !node.querySelector('.bit-icon')){
|
| 41 |
-
const svg = document.createElementNS("http://www.w3.org/2000/svg","svg");
|
| 42 |
-
svg.innerHTML = `<circle class="face" cx="80" cy="80" r="72"/>
|
| 43 |
-
<circle class="dot eye-left"/>
|
| 44 |
-
<circle class="dot eye-right"/>
|
| 45 |
-
<circle class="dot extra-dot" cx="80" cy="78" r="8"/>`;
|
| 46 |
-
svg.setAttribute('class','bit-icon');
|
| 47 |
-
svg.setAttribute('viewBox','0 0 160 160');
|
| 48 |
-
svg.style.width='30px';
|
| 49 |
-
svg.style.height='30px';
|
| 50 |
-
svg.style.marginTop='5px';
|
| 51 |
-
svg.style.display='block';
|
| 52 |
-
node.appendChild(svg);
|
| 53 |
-
|
| 54 |
-
// animação de "lendo"
|
| 55 |
-
const left = svg.querySelector('.eye-left');
|
| 56 |
-
const right = svg.querySelector('.eye-right');
|
| 57 |
-
const extra = svg.querySelector('.extra-dot');
|
| 58 |
-
|
| 59 |
-
let interval = setInterval(()=>{
|
| 60 |
-
const dx = (Math.random()*4)-2;
|
| 61 |
-
const dy = (Math.random()*4)-2;
|
| 62 |
-
left.setAttribute('cx',56+dx);
|
| 63 |
-
left.setAttribute('cy',62+dy);
|
| 64 |
-
right.setAttribute('cx',104+dx);
|
| 65 |
-
right.setAttribute('cy',62+dy);
|
| 66 |
-
extra.setAttribute('cx',80+dx);
|
| 67 |
-
extra.setAttribute('cy',78+dy);
|
| 68 |
-
},100);
|
| 69 |
-
|
| 70 |
-
setTimeout(()=>{
|
| 71 |
-
clearInterval(interval);
|
| 72 |
-
left.setAttribute('cx',56); left.setAttribute('cy',62);
|
| 73 |
-
right.setAttribute('cx',104); right.setAttribute('cy',62);
|
| 74 |
-
extra.setAttribute('cx',80); extra.setAttribute('cy',78);
|
| 75 |
-
},1200);
|
| 76 |
-
}
|
| 77 |
-
});
|
| 78 |
-
});
|
| 79 |
-
});
|
| 80 |
-
|
| 81 |
-
observer.observe(chatContainer,{childList:true, subtree:true});
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
document.addEventListener('DOMContentLoaded',addBitIconToBotMessages);
|
| 85 |
-
addBitIconToBotMessages();
|
| 86 |
-
</script>
|
| 87 |
-
|
| 88 |
-
<style>
|
| 89 |
-
.bit-icon .face{fill:#0b1020;}
|
| 90 |
-
.bit-icon .dot{fill:#fff; transition: all 500ms ease;}
|
| 91 |
-
.bit-icon .extra-dot{opacity:0; transform:translateY(10%); transition: all 500ms ease;}
|
| 92 |
-
.bit-icon.thinking .extra-dot{opacity:1; transform:translateY(0);}
|
| 93 |
-
.bit-icon.thinking .dot{animation: wave 1.4s infinite ease-in-out;}
|
| 94 |
-
@keyframes wave{0%,100%{transform:translateY(0);}50%{transform:translateY(-12%);}}
|
| 95 |
-
</style>
|
| 96 |
-
"""
|
| 97 |
|
| 98 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 99 |
|
|
@@ -106,9 +36,7 @@ body{background-color:#000;font-family:'Arial',sans-serif;}
|
|
| 106 |
""") as demo:
|
| 107 |
with gr.Sidebar():
|
| 108 |
gr.LoginButton()
|
| 109 |
-
|
| 110 |
chatbot.render()
|
| 111 |
-
gr.HTML(bit_icon_html)
|
| 112 |
|
| 113 |
if __name__=="__main__":
|
| 114 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
import time
|
| 4 |
|
| 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")
|
|
|
|
| 19 |
if chunk.choices and chunk.choices[0].delta.content:
|
| 20 |
token = chunk.choices[0].delta.content
|
| 21 |
response += token
|
|
|
|
| 22 |
|
| 23 |
+
# Yield por partes para dar efeito de digitação
|
| 24 |
+
for i in range(len(response)):
|
| 25 |
+
yield response[:i+1]
|
| 26 |
+
time.sleep(0.01) # velocidade do "typing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 29 |
|
|
|
|
| 36 |
""") as demo:
|
| 37 |
with gr.Sidebar():
|
| 38 |
gr.LoginButton()
|
|
|
|
| 39 |
chatbot.render()
|
|
|
|
| 40 |
|
| 41 |
if __name__=="__main__":
|
| 42 |
demo.launch()
|