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 |
# Função principal que chama o modelo
|
| 5 |
def respond(message, history: list[dict[str, str]], hf_token: gr.OAuthToken):
|
|
@@ -25,63 +26,281 @@ Keep a simple, approachable, and friendly tone otherwise."""
|
|
| 25 |
# JS para animações suaves
|
| 26 |
fade_js = """
|
| 27 |
<script>
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
node.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
node.style.
|
| 37 |
-
node.style.
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
});
|
| 41 |
});
|
| 42 |
-
});
|
| 43 |
|
| 44 |
-
document.addEventListener("DOMContentLoaded", ()=>{
|
| 45 |
const chatContainer = document.querySelector(".chat-interface");
|
| 46 |
-
if(chatContainer) observer.observe(chatContainer, {childList:true, subtree:true});
|
| 47 |
|
| 48 |
-
//
|
| 49 |
const txt = document.querySelector("textarea");
|
| 50 |
-
if(txt){
|
| 51 |
-
txt.addEventListener("
|
| 52 |
-
txt.style.transition = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
txt.style.backgroundColor = "#222";
|
| 54 |
-
setTimeout(()=>
|
|
|
|
|
|
|
|
|
|
| 55 |
});
|
| 56 |
}
|
| 57 |
|
| 58 |
-
//
|
| 59 |
const btn = document.querySelector(".send-btn");
|
| 60 |
-
if(btn){
|
| 61 |
-
btn.addEventListener("
|
| 62 |
-
btn.style.transform = "scale(
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
""") as demo:
|
| 86 |
|
| 87 |
# Login direto na página
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
import time
|
| 4 |
|
| 5 |
# Função principal que chama o modelo
|
| 6 |
def respond(message, history: list[dict[str, str]], hf_token: gr.OAuthToken):
|
|
|
|
| 26 |
# JS para animações suaves
|
| 27 |
fade_js = """
|
| 28 |
<script>
|
| 29 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 30 |
+
// Observer for chat messages
|
| 31 |
+
const observer = new MutationObserver(mutations => {
|
| 32 |
+
mutations.forEach(m => {
|
| 33 |
+
m.addedNodes.forEach(node => {
|
| 34 |
+
if (node.classList && node.classList.contains('chat-message')) {
|
| 35 |
+
// Enhanced message animation
|
| 36 |
+
node.style.opacity = 0;
|
| 37 |
+
node.style.transform = 'translateY(20px) scale(0.95)';
|
| 38 |
+
node.style.transition = 'opacity 0.5s ease, transform 0.5s ease, box-shadow 0.3s ease';
|
| 39 |
+
|
| 40 |
+
requestAnimationFrame(() => {
|
| 41 |
+
node.style.opacity = 1;
|
| 42 |
+
node.style.transform = 'translateY(0) scale(1)';
|
| 43 |
+
|
| 44 |
+
// Add subtle shadow on appearance
|
| 45 |
+
setTimeout(() => {
|
| 46 |
+
node.style.boxShadow = '0 4px 15px rgba(0,0,0,0.2)';
|
| 47 |
+
}, 500);
|
| 48 |
+
});
|
| 49 |
+
}
|
| 50 |
+
});
|
| 51 |
});
|
| 52 |
});
|
|
|
|
| 53 |
|
|
|
|
| 54 |
const chatContainer = document.querySelector(".chat-interface");
|
| 55 |
+
if (chatContainer) observer.observe(chatContainer, {childList: true, subtree: true});
|
| 56 |
|
| 57 |
+
// Enhanced typing animation for textarea
|
| 58 |
const txt = document.querySelector("textarea");
|
| 59 |
+
if (txt) {
|
| 60 |
+
txt.addEventListener("focus", () => {
|
| 61 |
+
txt.style.transition = "all 0.3s ease";
|
| 62 |
+
txt.style.transform = "translateY(-2px)";
|
| 63 |
+
txt.style.boxShadow = "0 5px 15px rgba(0,0,0,0.2)";
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
txt.addEventListener("blur", () => {
|
| 67 |
+
txt.style.transform = "translateY(0)";
|
| 68 |
+
txt.style.boxShadow = "0 2px 8px rgba(0,0,0,0.1)";
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
txt.addEventListener("input", () => {
|
| 72 |
txt.style.backgroundColor = "#222";
|
| 73 |
+
setTimeout(() => {
|
| 74 |
+
txt.style.transition = "background-color 0.5s ease";
|
| 75 |
+
txt.style.backgroundColor = "#1a1a1a";
|
| 76 |
+
}, 150);
|
| 77 |
});
|
| 78 |
}
|
| 79 |
|
| 80 |
+
// Enhanced button animation
|
| 81 |
const btn = document.querySelector(".send-btn");
|
| 82 |
+
if (btn) {
|
| 83 |
+
btn.addEventListener("mouseenter", () => {
|
| 84 |
+
btn.style.transform = "scale(1.05) rotate(2deg)";
|
| 85 |
+
btn.style.boxShadow = "0 5px 15px rgba(0,0,0,0.3)";
|
| 86 |
+
});
|
| 87 |
+
|
| 88 |
+
btn.addEventListener("mouseleave", () => {
|
| 89 |
+
btn.style.transform = "scale(1) rotate(0)";
|
| 90 |
+
btn.style.boxShadow = "0 2px 8px rgba(0,0,0,0.2)";
|
| 91 |
+
});
|
| 92 |
+
|
| 93 |
+
btn.addEventListener("mousedown", () => {
|
| 94 |
+
btn.style.transform = "scale(0.95) rotate(-1deg)";
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
btn.addEventListener("mouseup", () => {
|
| 98 |
+
btn.style.transform = "scale(1.05) rotate(2deg)";
|
| 99 |
});
|
| 100 |
+
|
| 101 |
+
btn.addEventListener("click", () => {
|
| 102 |
+
// Ripple effect
|
| 103 |
+
const ripple = document.createElement("span");
|
| 104 |
+
ripple.classList.add("ripple-effect");
|
| 105 |
+
btn.appendChild(ripple);
|
| 106 |
+
|
| 107 |
+
setTimeout(() => {
|
| 108 |
+
ripple.remove();
|
| 109 |
+
}, 600);
|
| 110 |
+
});
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// Add subtle pulse animation to login button
|
| 114 |
+
const loginBtn = document.querySelector(".gr-button.gr-login");
|
| 115 |
+
if (loginBtn) {
|
| 116 |
+
setInterval(() => {
|
| 117 |
+
loginBtn.style.boxShadow = "0 0 0 0 rgba(68, 68, 68, 0.7)";
|
| 118 |
+
setTimeout(() => {
|
| 119 |
+
loginBtn.style.transition = "box-shadow 0.5s ease";
|
| 120 |
+
loginBtn.style.boxShadow = "0 0 0 8px rgba(68, 68, 68, 0)";
|
| 121 |
+
}, 50);
|
| 122 |
+
}, 3000);
|
| 123 |
}
|
| 124 |
});
|
| 125 |
</script>
|
| 126 |
"""
|
| 127 |
|
| 128 |
with gr.Blocks(css="""
|
| 129 |
+
body {
|
| 130 |
+
background-color: #000;
|
| 131 |
+
font-family: 'Arial', sans-serif;
|
| 132 |
+
margin: 0;
|
| 133 |
+
padding: 0;
|
| 134 |
+
}
|
| 135 |
+
.gradio-container {
|
| 136 |
+
border-radius: 20px;
|
| 137 |
+
padding: 20px;
|
| 138 |
+
max-width: 700px;
|
| 139 |
+
margin: 30px auto;
|
| 140 |
+
background: linear-gradient(145deg, #0f0f0f, #1a1a1a);
|
| 141 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.4);
|
| 142 |
+
overflow: hidden;
|
| 143 |
+
}
|
| 144 |
+
.chat-message {
|
| 145 |
+
border-radius: 20px;
|
| 146 |
+
padding: 16px 20px;
|
| 147 |
+
margin: 12px 0;
|
| 148 |
+
display: flex;
|
| 149 |
+
flex-direction: column;
|
| 150 |
+
opacity: 0;
|
| 151 |
+
transition: all 0.3s ease;
|
| 152 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.15);
|
| 153 |
+
}
|
| 154 |
+
.chat-message.user {
|
| 155 |
+
background: linear-gradient(145deg, #252525, #1f1f1f);
|
| 156 |
+
color: #fff;
|
| 157 |
+
align-items: flex-end;
|
| 158 |
+
border-bottom-right-radius: 5px;
|
| 159 |
+
margin-left: 40px;
|
| 160 |
+
}
|
| 161 |
+
.chat-message.bot {
|
| 162 |
+
background: linear-gradient(145deg, #2e2e2e, #252525);
|
| 163 |
+
color: #fff;
|
| 164 |
+
align-items: flex-start;
|
| 165 |
+
border-bottom-left-radius: 5px;
|
| 166 |
+
margin-right: 40px;
|
| 167 |
+
}
|
| 168 |
+
textarea {
|
| 169 |
+
border: none;
|
| 170 |
+
outline: none;
|
| 171 |
+
border-radius: 25px;
|
| 172 |
+
padding: 16px 20px;
|
| 173 |
+
background-color: #1a1a1a;
|
| 174 |
+
color: #fff;
|
| 175 |
+
font-size: 16px;
|
| 176 |
+
flex: 1;
|
| 177 |
+
height: 60px;
|
| 178 |
+
box-sizing: border-box;
|
| 179 |
+
resize: none;
|
| 180 |
+
transition: all 0.3s ease;
|
| 181 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 182 |
+
}
|
| 183 |
+
.send-btn {
|
| 184 |
+
border: none;
|
| 185 |
+
border-radius: 25px;
|
| 186 |
+
background: linear-gradient(145deg, #555, #444);
|
| 187 |
+
color: #fff;
|
| 188 |
+
width: 60px;
|
| 189 |
+
height: 60px;
|
| 190 |
+
font-size: 20px;
|
| 191 |
+
display: flex;
|
| 192 |
+
align-items: center;
|
| 193 |
+
justify-content: center;
|
| 194 |
+
cursor: pointer;
|
| 195 |
+
margin-left: 12px;
|
| 196 |
+
transition: all 0.3s ease;
|
| 197 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
|
| 198 |
+
position: relative;
|
| 199 |
+
overflow: hidden;
|
| 200 |
+
}
|
| 201 |
+
.send-btn:hover {
|
| 202 |
+
background: linear-gradient(145deg, #666, #555);
|
| 203 |
+
transform: scale(1.05);
|
| 204 |
+
}
|
| 205 |
+
.gr-button.gr-login {
|
| 206 |
+
border-radius: 25px !important;
|
| 207 |
+
background: linear-gradient(145deg, #333, #222) !important;
|
| 208 |
+
color: #fff !important;
|
| 209 |
+
margin-bottom: 20px;
|
| 210 |
+
padding: 14px 24px;
|
| 211 |
+
transition: all 0.3s ease !important;
|
| 212 |
+
border: none !important;
|
| 213 |
+
}
|
| 214 |
+
.gr-button.gr-login:hover {
|
| 215 |
+
background: linear-gradient(145deg, #444, #333) !important;
|
| 216 |
+
transform: translateY(-2px);
|
| 217 |
+
}
|
| 218 |
+
.input-container {
|
| 219 |
+
display: flex;
|
| 220 |
+
margin-top: 15px;
|
| 221 |
+
}
|
| 222 |
+
.gr-chatbot {
|
| 223 |
+
border-radius: 15px;
|
| 224 |
+
overflow: hidden;
|
| 225 |
+
background: #1a1a1a;
|
| 226 |
+
padding: 15px;
|
| 227 |
+
box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);
|
| 228 |
+
}
|
| 229 |
+
.gr-box {
|
| 230 |
+
border-radius: 15px;
|
| 231 |
+
}
|
| 232 |
+
.gr-button-primary {
|
| 233 |
+
border-radius: 25px !important;
|
| 234 |
+
}
|
| 235 |
+
/* Ripple effect */
|
| 236 |
+
.ripple-effect {
|
| 237 |
+
position: absolute;
|
| 238 |
+
border-radius: 50%;
|
| 239 |
+
background-color: rgba(255, 255, 255, 0.3);
|
| 240 |
+
transform: scale(0);
|
| 241 |
+
animation: ripple 0.6s linear;
|
| 242 |
+
width: 100px;
|
| 243 |
+
height: 100px;
|
| 244 |
+
top: calc(50% - 50px);
|
| 245 |
+
left: calc(50% - 50px);
|
| 246 |
+
}
|
| 247 |
+
@keyframes ripple {
|
| 248 |
+
to {
|
| 249 |
+
transform: scale(2.5);
|
| 250 |
+
opacity: 0;
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
/* Scrollbar styling */
|
| 254 |
+
::-webkit-scrollbar {
|
| 255 |
+
width: 8px;
|
| 256 |
+
}
|
| 257 |
+
::-webkit-scrollbar-track {
|
| 258 |
+
background: #1a1a1a;
|
| 259 |
+
border-radius: 4px;
|
| 260 |
+
}
|
| 261 |
+
::-webkit-scrollbar-thumb {
|
| 262 |
+
background: #444;
|
| 263 |
+
border-radius: 4px;
|
| 264 |
+
}
|
| 265 |
+
::-webkit-scrollbar-thumb:hover {
|
| 266 |
+
background: #555;
|
| 267 |
+
}
|
| 268 |
+
/* Message typing indicator */
|
| 269 |
+
.typing-indicator {
|
| 270 |
+
display: inline-block;
|
| 271 |
+
position: relative;
|
| 272 |
+
width: 60px;
|
| 273 |
+
height: 20px;
|
| 274 |
+
}
|
| 275 |
+
.typing-dot {
|
| 276 |
+
display: inline-block;
|
| 277 |
+
width: 8px;
|
| 278 |
+
height: 8px;
|
| 279 |
+
border-radius: 50%;
|
| 280 |
+
background-color: #888;
|
| 281 |
+
position: absolute;
|
| 282 |
+
animation: typing-animation 1.4s infinite ease-in-out;
|
| 283 |
+
}
|
| 284 |
+
.typing-dot:nth-child(1) {
|
| 285 |
+
left: 0;
|
| 286 |
+
animation-delay: 0s;
|
| 287 |
+
}
|
| 288 |
+
.typing-dot:nth-child(2) {
|
| 289 |
+
left: 15px;
|
| 290 |
+
animation-delay: 0.2s;
|
| 291 |
+
}
|
| 292 |
+
.typing-dot:nth-child(3) {
|
| 293 |
+
left: 30px;
|
| 294 |
+
animation-delay: 0.4s;
|
| 295 |
+
}
|
| 296 |
+
@keyframes typing-animation {
|
| 297 |
+
0%, 60%, 100% {
|
| 298 |
+
transform: translateY(0);
|
| 299 |
+
}
|
| 300 |
+
30% {
|
| 301 |
+
transform: translateY(-5px);
|
| 302 |
+
}
|
| 303 |
+
}
|
| 304 |
""") as demo:
|
| 305 |
|
| 306 |
# Login direto na página
|