Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,181 +3,65 @@ from huggingface_hub import InferenceClient
|
|
| 3 |
from typing import List, Dict
|
| 4 |
|
| 5 |
# ---------------------------
|
| 6 |
-
#
|
| 7 |
# ---------------------------
|
| 8 |
-
|
| 9 |
custom_css = """
|
| 10 |
-
/*
|
| 11 |
-
/* CORE SYSTEM ARCHITECTURE */
|
| 12 |
-
/* βββββββββββββββββββββββββββββββββββββββββββ */
|
| 13 |
-
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');
|
| 14 |
-
:root {
|
| 15 |
-
--primary-glow: #00fff7;
|
| 16 |
-
--secondary-glow: #7b2ff7;
|
| 17 |
-
--danger-glow: #ff006e;
|
| 18 |
-
--neural-dark: #0a0e27;
|
| 19 |
-
--glass-bg: rgba(255, 255, 255, 0.03);
|
| 20 |
-
}
|
| 21 |
-
* {
|
| 22 |
-
font-family: 'Orbitron', monospace !important;
|
| 23 |
-
}
|
| 24 |
body, .gradio-container {
|
| 25 |
-
|
| 26 |
-
padding: 0;
|
| 27 |
-
background: var(--neural-dark) !important;
|
| 28 |
color: white !important;
|
| 29 |
-
position: relative;
|
| 30 |
-
overflow-x: hidden;
|
| 31 |
-
}
|
| 32 |
-
.gradio-container::before {
|
| 33 |
-
content: "";
|
| 34 |
-
position: fixed;
|
| 35 |
-
top: 0;
|
| 36 |
-
left: 0;
|
| 37 |
-
width: 100%;
|
| 38 |
-
height: 100%;
|
| 39 |
-
background:
|
| 40 |
-
radial-gradient(circle at 20% 50%, rgba(123, 47, 247, 0.15) 0%, transparent 50%),
|
| 41 |
-
radial-gradient(circle at 80% 80%, rgba(0, 255, 247, 0.15) 0%, transparent 50%),
|
| 42 |
-
radial-gradient(circle at 40% 20%, rgba(255, 0, 110, 0.1) 0%, transparent 50%);
|
| 43 |
-
animation: backgroundPulse 15s ease-in-out infinite;
|
| 44 |
-
pointer-events: none;
|
| 45 |
-
z-index: 0;
|
| 46 |
-
}
|
| 47 |
-
@keyframes backgroundPulse {
|
| 48 |
-
0%, 100% { opacity: 1; transform: scale(1); }
|
| 49 |
-
50% { opacity: 0.8; transform: scale(1.1); }
|
| 50 |
-
}
|
| 51 |
-
.gradio-container::after {
|
| 52 |
-
content: "";
|
| 53 |
-
position: fixed;
|
| 54 |
-
top: 0;
|
| 55 |
-
left: 0;
|
| 56 |
-
width: 100%;
|
| 57 |
-
height: 100%;
|
| 58 |
-
background-image:
|
| 59 |
-
radial-gradient(2px 2px at 20% 30%, white, transparent),
|
| 60 |
-
radial-gradient(2px 2px at 60% 70%, var(--primary-glow), transparent),
|
| 61 |
-
radial-gradient(1px 1px at 50% 50%, var(--secondary-glow), transparent),
|
| 62 |
-
radial-gradient(1px 1px at 80% 10%, var(--danger-glow), transparent);
|
| 63 |
-
background-size: 200% 200%;
|
| 64 |
-
animation: particleFloat 20s linear infinite;
|
| 65 |
-
opacity: 0.4;
|
| 66 |
-
pointer-events: none;
|
| 67 |
-
z-index: 0;
|
| 68 |
-
}
|
| 69 |
-
@keyframes particleFloat {
|
| 70 |
-
0% { background-position: 0% 0%; }
|
| 71 |
-
100% { background-position: 100% 100%; }
|
| 72 |
}
|
|
|
|
| 73 |
#title {
|
| 74 |
-
|
| 75 |
-
font-size: 48px;
|
| 76 |
font-weight: 900;
|
| 77 |
text-align: center;
|
| 78 |
-
margin:
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
-webkit-background-clip: text;
|
| 82 |
-
-webkit-text-fill-color: transparent;
|
| 83 |
-
background-clip: text;
|
| 84 |
-
animation: gradientFlow 6s linear infinite, titlePulse 3s ease-in-out infinite;
|
| 85 |
-
filter: drop-shadow(0 0 20px var(--primary-glow)) drop-shadow(0 0 40px var(--secondary-glow));
|
| 86 |
-
letter-spacing: 4px;
|
| 87 |
-
z-index: 10;
|
| 88 |
}
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
100% { background-position: 300% 50%; }
|
| 92 |
-
}
|
| 93 |
-
@keyframes titlePulse {
|
| 94 |
-
0%, 100% { transform: scale(1); }
|
| 95 |
-
50% { transform: scale(1.02); }
|
| 96 |
-
}
|
| 97 |
-
#title::before {
|
| 98 |
-
content: "";
|
| 99 |
-
position: absolute;
|
| 100 |
-
top: -10px;
|
| 101 |
-
left: 50%;
|
| 102 |
-
transform: translateX(-50%);
|
| 103 |
-
width: 80%;
|
| 104 |
-
height: 3px;
|
| 105 |
-
background: linear-gradient(90deg, transparent, var(--primary-glow), transparent);
|
| 106 |
-
animation: scanLine 3s linear infinite;
|
| 107 |
-
}
|
| 108 |
-
@keyframes scanLine {
|
| 109 |
-
0%, 100% { opacity: 0; }
|
| 110 |
-
50% { opacity: 1; }
|
| 111 |
-
}
|
| 112 |
-
.chatbot {
|
| 113 |
border-radius: 20px !important;
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
box-shadow:
|
| 118 |
-
0 8px 32px rgba(0, 0, 0, 0.5),
|
| 119 |
-
inset 0 0 40px rgba(0, 255, 247, 0.05),
|
| 120 |
-
0 0 80px rgba(123, 47, 247, 0.3) !important;
|
| 121 |
-
position: relative;
|
| 122 |
-
overflow: hidden;
|
| 123 |
-
animation: chatbotIntro 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
|
| 124 |
-
z-index: 10;
|
| 125 |
-
}
|
| 126 |
-
@keyframes chatbotIntro {
|
| 127 |
-
0% { opacity: 0; transform: translateY(30px) scale(0.95); }
|
| 128 |
-
100% { opacity: 1; transform: translateY(0) scale(1); }
|
| 129 |
}
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
border-radius: 15px
|
| 134 |
-
padding:
|
| 135 |
-
|
| 136 |
-
0 4px 15px rgba(0, 255, 247, 0.3),
|
| 137 |
-
inset 0 0 20px rgba(0, 255, 247, 0.1) !important;
|
| 138 |
-
position: relative;
|
| 139 |
-
overflow: hidden;
|
| 140 |
-
transition: all 0.3s ease;
|
| 141 |
}
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
border-radius: 15px
|
| 146 |
-
padding:
|
| 147 |
-
|
| 148 |
-
0 4px 15px rgba(123, 47, 247, 0.3),
|
| 149 |
-
inset 0 0 20px rgba(123, 47, 234, 0.1) !important;
|
| 150 |
-
position: relative;
|
| 151 |
-
overflow: hidden;
|
| 152 |
-
transition: all 0.3s ease;
|
| 153 |
}
|
| 154 |
-
|
|
|
|
| 155 |
border-radius: 15px !important;
|
| 156 |
-
background:
|
| 157 |
backdrop-filter: blur(10px) !important;
|
| 158 |
-
border: 1px solid rgba(0, 255, 247, 0.3) !important;
|
| 159 |
color: white !important;
|
| 160 |
-
padding: 15px !important;
|
| 161 |
-
box-shadow:
|
| 162 |
-
0 4px 15px rgba(0, 0, 0, 0.3),
|
| 163 |
-
inset 0 0 20px rgba(0, 255, 247, 0.05) !important;
|
| 164 |
-
transition: all 0.3s ease;
|
| 165 |
-
font-size: 14px !important;
|
| 166 |
}
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
transform:
|
|
|
|
| 174 |
}
|
| 175 |
"""
|
| 176 |
|
| 177 |
# ---------------------------
|
| 178 |
-
#
|
| 179 |
# ---------------------------
|
| 180 |
-
|
| 181 |
def respond(
|
| 182 |
message,
|
| 183 |
history: List[Dict[str, str]],
|
|
@@ -185,12 +69,15 @@ def respond(
|
|
| 185 |
max_tokens,
|
| 186 |
temperature,
|
| 187 |
top_p,
|
| 188 |
-
hf_token,
|
| 189 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
system_message = (
|
| 191 |
-
"You are a
|
| 192 |
-
"
|
| 193 |
-
"Maintain a professional and sophisticated tone."
|
| 194 |
)
|
| 195 |
|
| 196 |
client = InferenceClient(
|
|
@@ -213,81 +100,59 @@ def respond(
|
|
| 213 |
):
|
| 214 |
choices = getattr(msg, "choices", [])
|
| 215 |
token = ""
|
| 216 |
-
|
| 217 |
if len(choices) and getattr(choices[0].delta, "content", None):
|
| 218 |
token = choices[0].delta.content
|
| 219 |
-
|
| 220 |
response += token
|
| 221 |
yield response
|
| 222 |
|
| 223 |
# ---------------------------
|
| 224 |
-
#
|
| 225 |
# ---------------------------
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
gr.HTML("<div id='title'>NEURAL QUANTUM INTERFACE</div>")
|
| 229 |
|
| 230 |
with gr.Row():
|
| 231 |
with gr.Column(scale=4):
|
| 232 |
chatbot = gr.Chatbot(
|
| 233 |
-
label="
|
| 234 |
-
|
| 235 |
-
height=
|
| 236 |
-
|
| 237 |
)
|
| 238 |
|
| 239 |
with gr.Row():
|
| 240 |
msg = gr.Textbox(
|
| 241 |
-
|
| 242 |
-
placeholder="Initialize command sequence...",
|
| 243 |
scale=4
|
| 244 |
)
|
| 245 |
-
submit = gr.Button("
|
| 246 |
|
| 247 |
with gr.Column(scale=1):
|
| 248 |
gr.LoginButton()
|
| 249 |
-
gr.Markdown("### SYSTEM PARAMETERS")
|
| 250 |
-
|
| 251 |
system_message_box = gr.Textbox(
|
| 252 |
-
value="
|
| 253 |
-
label="
|
| 254 |
-
)
|
| 255 |
-
max_tokens = gr.Slider(
|
| 256 |
-
minimum=1,
|
| 257 |
-
maximum=2048,
|
| 258 |
-
value=512,
|
| 259 |
-
step=1,
|
| 260 |
-
label="TOKEN LIMIT"
|
| 261 |
-
)
|
| 262 |
-
temperature = gr.Slider(
|
| 263 |
-
minimum=0.1,
|
| 264 |
-
maximum=2.0,
|
| 265 |
-
value=0.7,
|
| 266 |
-
step=0.1,
|
| 267 |
-
label="THERMAL INDEX"
|
| 268 |
-
)
|
| 269 |
-
top_p = gr.Slider(
|
| 270 |
-
minimum=0.1,
|
| 271 |
-
maximum=1.0,
|
| 272 |
-
value=0.9,
|
| 273 |
-
step=0.05,
|
| 274 |
-
label="PROBABILITY THRESHOLD"
|
| 275 |
)
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
| 278 |
|
| 279 |
# Event handlers
|
| 280 |
msg.submit(
|
| 281 |
respond,
|
| 282 |
-
[msg, chatbot, system_message_box,
|
| 283 |
[chatbot]
|
| 284 |
)
|
| 285 |
submit.click(
|
| 286 |
respond,
|
| 287 |
-
[msg, chatbot, system_message_box,
|
| 288 |
[chatbot]
|
| 289 |
)
|
| 290 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 291 |
|
|
|
|
|
|
|
|
|
|
| 292 |
if __name__ == "__main__":
|
| 293 |
demo.launch()
|
|
|
|
| 3 |
from typing import List, Dict
|
| 4 |
|
| 5 |
# ---------------------------
|
| 6 |
+
# L U A U S T A T I C T H E M E
|
| 7 |
# ---------------------------
|
|
|
|
| 8 |
custom_css = """
|
| 9 |
+
/* PAGE BACKGROUND */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
body, .gradio-container {
|
| 11 |
+
background: linear-gradient(135deg, #141e30, #243b55) !important;
|
|
|
|
|
|
|
| 12 |
color: white !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
+
/* TITLE */
|
| 15 |
#title {
|
| 16 |
+
font-size: 42px;
|
|
|
|
| 17 |
font-weight: 900;
|
| 18 |
text-align: center;
|
| 19 |
+
margin-bottom: 10px;
|
| 20 |
+
color: #00f7ff;
|
| 21 |
+
text-shadow: 0 0 20px #00f7ff;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
+
/* CHATBOT BOX */
|
| 24 |
+
.gr-chatbot {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
border-radius: 20px !important;
|
| 26 |
+
box-shadow: 0 0 25px rgba(0,255,255,0.4) !important;
|
| 27 |
+
background: rgba(0, 0, 0, 0.25) !important;
|
| 28 |
+
backdrop-filter: blur(10px) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
+
/* USER MESSAGES */
|
| 31 |
+
.message.user {
|
| 32 |
+
background: rgba(0, 200, 255, 0.3) !important;
|
| 33 |
+
border-radius: 15px !important;
|
| 34 |
+
padding: 10px !important;
|
| 35 |
+
animation: fadeIn 0.3s ease-out;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
+
/* BOT MESSAGES */
|
| 38 |
+
.message.bot {
|
| 39 |
+
background: rgba(0, 255, 110, 0.25) !important;
|
| 40 |
+
border-radius: 15px !important;
|
| 41 |
+
padding: 10px !important;
|
| 42 |
+
animation: slideUp 0.4s ease-out;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
+
/* INPUT TEXTBOX */
|
| 45 |
+
textarea {
|
| 46 |
border-radius: 15px !important;
|
| 47 |
+
background: rgba(255,255,255,0.1) !important;
|
| 48 |
backdrop-filter: blur(10px) !important;
|
|
|
|
| 49 |
color: white !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
+
/* ANIMATIONS */
|
| 52 |
+
@keyframes fadeIn {
|
| 53 |
+
from { opacity: 0; transform: translateX(10px); }
|
| 54 |
+
to { opacity: 1; transform: translateX(0); }
|
| 55 |
+
}
|
| 56 |
+
@keyframes slideUp {
|
| 57 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 58 |
+
to { opacity: 1; transform: translateY(0); }
|
| 59 |
}
|
| 60 |
"""
|
| 61 |
|
| 62 |
# ---------------------------
|
| 63 |
+
# L U A U B O T L O G I C
|
| 64 |
# ---------------------------
|
|
|
|
| 65 |
def respond(
|
| 66 |
message,
|
| 67 |
history: List[Dict[str, str]],
|
|
|
|
| 69 |
max_tokens,
|
| 70 |
temperature,
|
| 71 |
top_p,
|
| 72 |
+
hf_token: gr.OAuthToken,
|
| 73 |
):
|
| 74 |
+
"""
|
| 75 |
+
Generates the AI response using HuggingFace InferenceClient with streaming.
|
| 76 |
+
"""
|
| 77 |
+
# Inject Luau personality
|
| 78 |
system_message = (
|
| 79 |
+
"You are Luau, a friendly, stylish AI assistant. "
|
| 80 |
+
"You speak clearly and helpfully. Respond in a calm and fun tone."
|
|
|
|
| 81 |
)
|
| 82 |
|
| 83 |
client = InferenceClient(
|
|
|
|
| 100 |
):
|
| 101 |
choices = getattr(msg, "choices", [])
|
| 102 |
token = ""
|
|
|
|
| 103 |
if len(choices) and getattr(choices[0].delta, "content", None):
|
| 104 |
token = choices[0].delta.content
|
|
|
|
| 105 |
response += token
|
| 106 |
yield response
|
| 107 |
|
| 108 |
# ---------------------------
|
| 109 |
+
# U I + A N I M A T I O N S
|
| 110 |
# ---------------------------
|
| 111 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 112 |
+
gr.HTML("<div id='title'>β Meet Luau β Your AI Companion β</div>")
|
|
|
|
| 113 |
|
| 114 |
with gr.Row():
|
| 115 |
with gr.Column(scale=4):
|
| 116 |
chatbot = gr.Chatbot(
|
| 117 |
+
label="LUAU AI",
|
| 118 |
+
elem_classes=["gr-chatbot"],
|
| 119 |
+
height=500,
|
| 120 |
+
type="messages"
|
| 121 |
)
|
| 122 |
|
| 123 |
with gr.Row():
|
| 124 |
msg = gr.Textbox(
|
| 125 |
+
placeholder="Type a message...",
|
|
|
|
| 126 |
scale=4
|
| 127 |
)
|
| 128 |
+
submit = gr.Button("Send", scale=1)
|
| 129 |
|
| 130 |
with gr.Column(scale=1):
|
| 131 |
gr.LoginButton()
|
|
|
|
|
|
|
| 132 |
system_message_box = gr.Textbox(
|
| 133 |
+
value="You are Luau, a friendly AI.",
|
| 134 |
+
label="System Message"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
)
|
| 136 |
+
max_tokens_slider = gr.Slider(1, 2048, value=450, step=1, label="Max Tokens")
|
| 137 |
+
temperature_slider = gr.Slider(0.1, 4.0, value=1.0, step=0.1, label="Temperature")
|
| 138 |
+
top_p_slider = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="Top-p")
|
| 139 |
+
clear = gr.Button("Clear Chat")
|
| 140 |
|
| 141 |
# Event handlers
|
| 142 |
msg.submit(
|
| 143 |
respond,
|
| 144 |
+
[msg, chatbot, system_message_box, max_tokens_slider, temperature_slider, top_p_slider, gr.LoginButton()],
|
| 145 |
[chatbot]
|
| 146 |
)
|
| 147 |
submit.click(
|
| 148 |
respond,
|
| 149 |
+
[msg, chatbot, system_message_box, max_tokens_slider, temperature_slider, top_p_slider, gr.LoginButton()],
|
| 150 |
[chatbot]
|
| 151 |
)
|
| 152 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 153 |
|
| 154 |
+
# ---------------------------
|
| 155 |
+
# Launch
|
| 156 |
+
# ---------------------------
|
| 157 |
if __name__ == "__main__":
|
| 158 |
demo.launch()
|