Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from huggingface_hub import InferenceClient
|
|
| 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 |
system_message = """You are BitAI (or Bit for short), a friendly chatbot created by the user "Sal".
|
| 8 |
-
You respond politely, refuse
|
| 9 |
|
| 10 |
messages = [{"role": "system", "content": system_message}]
|
| 11 |
messages.extend(history)
|
|
@@ -17,21 +17,42 @@ You respond politely, refuse inapropriate requests, and keep a friendly tone."""
|
|
| 17 |
response += token
|
| 18 |
yield response
|
| 19 |
|
| 20 |
-
# JS para
|
| 21 |
fade_js = """
|
| 22 |
<script>
|
| 23 |
document.addEventListener("DOMContentLoaded", () => {
|
| 24 |
-
// Título animado
|
| 25 |
const grContainer = document.querySelector(".gradio-container");
|
|
|
|
| 26 |
if(grContainer && !document.querySelector(".chat-title")) {
|
| 27 |
const titleContainer = document.createElement("div");
|
| 28 |
titleContainer.className = "title-container";
|
| 29 |
titleContainer.innerHTML = `
|
| 30 |
-
<
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
`;
|
| 33 |
grContainer.insertBefore(titleContainer, grContainer.firstChild);
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
// Startup message
|
|
@@ -74,26 +95,32 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 74 |
document.querySelectorAll("button, .chat-message, textarea, .gr-button.gr-login, .chat-title, .chat-subtitle, .startup-message, .gr-chatbot").forEach(bounce);
|
| 75 |
});
|
| 76 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
"""
|
| 78 |
|
| 79 |
-
# Gradio interface
|
| 80 |
with gr.Blocks(css="""
|
| 81 |
body{background:#000;margin:0;padding:0;font-family:'Inter','Manrope','Outfit',sans-serif;}
|
| 82 |
.gradio-container{border-radius:20px;padding:20px;max-width:700px;margin:30px auto;background:linear-gradient(145deg,#0f0f0f,#1a1a1a);box-shadow:0 10px 30px rgba(0,0,0,0.4);transition:transform 0.3s;}
|
| 83 |
-
.title-container{opacity:0;transform:translateY(-20px);transition:0.5s;}
|
| 84 |
-
.chat-title{font-size:32px;color:#fff;margin-bottom:10px;cursor:pointer;transition:0.3s;}
|
| 85 |
-
.chat-subtitle{font-size:14px;color:#aaa;cursor:pointer;transition:0.3s;}
|
| 86 |
textarea{border:none;border-radius:25px;padding:14px 20px 14px 20px;background:#1a1a1a;color:#fff;font-size:16px;width:100%;height:56px;transition:0.3s;}
|
| 87 |
.send-btn{border:none;border-radius:20px;background:linear-gradient(145deg,#555,#444);color:#fff;width:40px;height:40px;position:absolute;right:8px;top:8px;cursor:pointer;transition:0.3s;}
|
| 88 |
.chat-message{border-radius:20px;padding:16px;margin:12px 0;opacity:0;transition:0.5s;box-shadow:0 4px 10px rgba(0,0,0,0.15);}
|
| 89 |
.chat-message.user{background:linear-gradient(145deg,#252525,#1f1f1f);color:#fff;align-items:flex-end;margin-left:40px;}
|
| 90 |
.chat-message.bot{background:linear-gradient(145deg,#2e2e2e,#252525);color:#fff;align-items:flex-start;margin-right:40px;}
|
| 91 |
-
.startup-message{opacity:0;transform:translateY(20px);transition:0.5s;margin:20px 0;display:flex;justify-content:center;cursor:pointer;}
|
| 92 |
-
.startup-content{display:flex;align-items:center;background:linear-gradient(145deg,#2e2e2e,#252525);padding:20px;border-radius:20px;box-shadow:0 4px 15px rgba(0,0,0,0.2);}
|
| 93 |
-
.startup-icon{font-size:32px;margin-right:15px;}
|
| 94 |
-
.startup-title{font-weight:600;font-size:18px;color:#fff;}
|
| 95 |
-
.startup-subtitle{font-size:16px;color:#eee;}
|
| 96 |
-
.startup-note{font-size:12px;color:#aaa;font-style:italic;}
|
| 97 |
""") as demo:
|
| 98 |
|
| 99 |
gr.LoginButton()
|
|
|
|
| 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 |
system_message = """You are BitAI (or Bit for short), a friendly chatbot created by the user "Sal".
|
| 8 |
+
You respond politely, refuse inappropriate requests, and keep a friendly tone."""
|
| 9 |
|
| 10 |
messages = [{"role": "system", "content": system_message}]
|
| 11 |
messages.extend(history)
|
|
|
|
| 17 |
response += token
|
| 18 |
yield response
|
| 19 |
|
| 20 |
+
# JS + HTML para título animado e botão de fechar
|
| 21 |
fade_js = """
|
| 22 |
<script>
|
| 23 |
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
| 24 |
const grContainer = document.querySelector(".gradio-container");
|
| 25 |
+
|
| 26 |
if(grContainer && !document.querySelector(".chat-title")) {
|
| 27 |
const titleContainer = document.createElement("div");
|
| 28 |
titleContainer.className = "title-container";
|
| 29 |
titleContainer.innerHTML = `
|
| 30 |
+
<div class="title-inner">
|
| 31 |
+
<h1 class="chat-title">Talk with BitAI (W.I.P)</h1>
|
| 32 |
+
<p class="chat-subtitle">Still updating, might not know everything, filter slightly broken</p>
|
| 33 |
+
<button class="close-title-btn">
|
| 34 |
+
<svg width="24" height="24" viewBox="0 0 24 24">
|
| 35 |
+
<path fill="#fff" d="M12 16l-6-6h12z"/>
|
| 36 |
+
</svg>
|
| 37 |
+
</button>
|
| 38 |
+
</div>
|
| 39 |
`;
|
| 40 |
grContainer.insertBefore(titleContainer, grContainer.firstChild);
|
| 41 |
+
|
| 42 |
+
// animação de aparecer
|
| 43 |
+
setTimeout(() => {
|
| 44 |
+
titleContainer.style.opacity = "1";
|
| 45 |
+
titleContainer.style.transform = "translateY(0)";
|
| 46 |
+
}, 100);
|
| 47 |
+
|
| 48 |
+
// botão de fechar
|
| 49 |
+
const closeBtn = titleContainer.querySelector(".close-title-btn");
|
| 50 |
+
closeBtn.addEventListener("click", () => {
|
| 51 |
+
titleContainer.style.transition = "all 0.4s ease";
|
| 52 |
+
titleContainer.style.opacity = "0";
|
| 53 |
+
titleContainer.style.transform = "translateY(-20px)";
|
| 54 |
+
setTimeout(() => titleContainer.remove(), 400);
|
| 55 |
+
});
|
| 56 |
}
|
| 57 |
|
| 58 |
// Startup message
|
|
|
|
| 95 |
document.querySelectorAll("button, .chat-message, textarea, .gr-button.gr-login, .chat-title, .chat-subtitle, .startup-message, .gr-chatbot").forEach(bounce);
|
| 96 |
});
|
| 97 |
</script>
|
| 98 |
+
|
| 99 |
+
<style>
|
| 100 |
+
.title-container { text-align:center; margin-bottom:25px; opacity:0; transform:translateY(-20px); transition:0.5s; position:relative; }
|
| 101 |
+
.title-inner { display:inline-block; position:relative; }
|
| 102 |
+
.chat-title { font-size:32px; color:#fff; margin-bottom:10px; cursor:pointer; }
|
| 103 |
+
.chat-subtitle { font-size:14px; color:#aaa; margin-bottom:10px; }
|
| 104 |
+
.close-title-btn { position:absolute; right:-10px; top:-10px; background:transparent; border:none; cursor:pointer; padding:5px; transition: transform 0.2s; }
|
| 105 |
+
.close-title-btn:hover { transform:scale(1.2); }
|
| 106 |
+
.startup-message { opacity:0; transform:translateY(20px); transition:0.5s; margin:20px 0; display:flex; justify-content:center; cursor:pointer; }
|
| 107 |
+
.startup-content { display:flex; align-items:center; background:linear-gradient(145deg,#2e2e2e,#252525); padding:20px; border-radius:20px; box-shadow:0 4px 15px rgba(0,0,0,0.2); }
|
| 108 |
+
.startup-icon { font-size:32px; margin-right:15px; }
|
| 109 |
+
.startup-title { font-weight:600; font-size:18px; color:#fff; }
|
| 110 |
+
.startup-subtitle { font-size:16px; color:#eee; }
|
| 111 |
+
.startup-note { font-size:12px; color:#aaa; font-style:italic; }
|
| 112 |
+
</style>
|
| 113 |
"""
|
| 114 |
|
| 115 |
+
# Gradio interface completa
|
| 116 |
with gr.Blocks(css="""
|
| 117 |
body{background:#000;margin:0;padding:0;font-family:'Inter','Manrope','Outfit',sans-serif;}
|
| 118 |
.gradio-container{border-radius:20px;padding:20px;max-width:700px;margin:30px auto;background:linear-gradient(145deg,#0f0f0f,#1a1a1a);box-shadow:0 10px 30px rgba(0,0,0,0.4);transition:transform 0.3s;}
|
|
|
|
|
|
|
|
|
|
| 119 |
textarea{border:none;border-radius:25px;padding:14px 20px 14px 20px;background:#1a1a1a;color:#fff;font-size:16px;width:100%;height:56px;transition:0.3s;}
|
| 120 |
.send-btn{border:none;border-radius:20px;background:linear-gradient(145deg,#555,#444);color:#fff;width:40px;height:40px;position:absolute;right:8px;top:8px;cursor:pointer;transition:0.3s;}
|
| 121 |
.chat-message{border-radius:20px;padding:16px;margin:12px 0;opacity:0;transition:0.5s;box-shadow:0 4px 10px rgba(0,0,0,0.15);}
|
| 122 |
.chat-message.user{background:linear-gradient(145deg,#252525,#1f1f1f);color:#fff;align-items:flex-end;margin-left:40px;}
|
| 123 |
.chat-message.bot{background:linear-gradient(145deg,#2e2e2e,#252525);color:#fff;align-items:flex-start;margin-right:40px;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
""") as demo:
|
| 125 |
|
| 126 |
gr.LoginButton()
|