Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -171,6 +171,21 @@ body {
|
|
| 171 |
font-size: 16px;
|
| 172 |
margin-top: 20px;
|
| 173 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
"""
|
| 175 |
|
| 176 |
def respond(
|
|
@@ -186,7 +201,7 @@ def respond(
|
|
| 186 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 187 |
"""
|
| 188 |
if not hf_token:
|
| 189 |
-
yield "π Please login with your Hugging Face token to start chatting!"
|
| 190 |
return
|
| 191 |
|
| 192 |
try:
|
|
@@ -234,6 +249,9 @@ with gr.Blocks(
|
|
| 234 |
</div>
|
| 235 |
""")
|
| 236 |
|
|
|
|
|
|
|
|
|
|
| 237 |
with gr.Row():
|
| 238 |
with gr.Column(scale=1, min_width=280):
|
| 239 |
# Sidebar content
|
|
@@ -243,8 +261,15 @@ with gr.Blocks(
|
|
| 243 |
</div>
|
| 244 |
""")
|
| 245 |
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
|
|
|
| 248 |
system_input = gr.Textbox(
|
| 249 |
value=system_message,
|
| 250 |
label="π€ System Role",
|
|
@@ -283,12 +308,13 @@ with gr.Blocks(
|
|
| 283 |
<li>Higher temperature = more creative</li>
|
| 284 |
<li>Lower temperature = more focused</li>
|
| 285 |
<li>Adjust max tokens for response length</li>
|
|
|
|
| 286 |
</ul>
|
| 287 |
</div>
|
| 288 |
""")
|
| 289 |
|
| 290 |
with gr.Column(scale=4):
|
| 291 |
-
# Chat interface
|
| 292 |
chatbot = gr.ChatInterface(
|
| 293 |
respond,
|
| 294 |
type="messages",
|
|
@@ -298,19 +324,28 @@ with gr.Blocks(
|
|
| 298 |
temperature_input,
|
| 299 |
top_p_input
|
| 300 |
],
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
["Help me plan a healthy meal for today"],
|
| 305 |
-
["What are some good productivity tips?"]
|
| 306 |
-
],
|
| 307 |
-
submit_btn="π Send"
|
| 308 |
)
|
| 309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
if __name__ == "__main__":
|
| 311 |
demo.launch(
|
| 312 |
show_api=False,
|
| 313 |
share=False,
|
| 314 |
-
|
| 315 |
-
|
| 316 |
)
|
|
|
|
| 171 |
font-size: 16px;
|
| 172 |
margin-top: 20px;
|
| 173 |
}
|
| 174 |
+
|
| 175 |
+
.warning-message {
|
| 176 |
+
background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
|
| 177 |
+
color: white;
|
| 178 |
+
padding: 12px;
|
| 179 |
+
border-radius: 12px;
|
| 180 |
+
margin: 10px 0;
|
| 181 |
+
text-align: center;
|
| 182 |
+
animation: pulse 2s infinite;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
@keyframes pulse {
|
| 186 |
+
0%, 100% { opacity: 1; }
|
| 187 |
+
50% { opacity: 0.8; }
|
| 188 |
+
}
|
| 189 |
"""
|
| 190 |
|
| 191 |
def respond(
|
|
|
|
| 201 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 202 |
"""
|
| 203 |
if not hf_token:
|
| 204 |
+
yield "π Please login with your Hugging Face token to start chatting! Click the login button in the sidebar."
|
| 205 |
return
|
| 206 |
|
| 207 |
try:
|
|
|
|
| 249 |
</div>
|
| 250 |
""")
|
| 251 |
|
| 252 |
+
# Store the token as a state
|
| 253 |
+
token_state = gr.State()
|
| 254 |
+
|
| 255 |
with gr.Row():
|
| 256 |
with gr.Column(scale=1, min_width=280):
|
| 257 |
# Sidebar content
|
|
|
|
| 261 |
</div>
|
| 262 |
""")
|
| 263 |
|
| 264 |
+
# Login section
|
| 265 |
+
login = gr.LoginButton()
|
| 266 |
+
gr.Markdown("""
|
| 267 |
+
<div class="warning-message">
|
| 268 |
+
π Login required to use the AI assistant
|
| 269 |
+
</div>
|
| 270 |
+
""")
|
| 271 |
|
| 272 |
+
# Settings
|
| 273 |
system_input = gr.Textbox(
|
| 274 |
value=system_message,
|
| 275 |
label="π€ System Role",
|
|
|
|
| 308 |
<li>Higher temperature = more creative</li>
|
| 309 |
<li>Lower temperature = more focused</li>
|
| 310 |
<li>Adjust max tokens for response length</li>
|
| 311 |
+
<li>Login with Hugging Face token required</li>
|
| 312 |
</ul>
|
| 313 |
</div>
|
| 314 |
""")
|
| 315 |
|
| 316 |
with gr.Column(scale=4):
|
| 317 |
+
# Chat interface without examples to avoid caching issues
|
| 318 |
chatbot = gr.ChatInterface(
|
| 319 |
respond,
|
| 320 |
type="messages",
|
|
|
|
| 324 |
temperature_input,
|
| 325 |
top_p_input
|
| 326 |
],
|
| 327 |
+
submit_btn="π Send",
|
| 328 |
+
title=None, # We already have our own title
|
| 329 |
+
description=None # We already have our own description
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
)
|
| 331 |
|
| 332 |
+
# Function to handle login
|
| 333 |
+
def handle_login(token):
|
| 334 |
+
if token:
|
| 335 |
+
return token, "β
Successfully logged in! You can now chat with the AI."
|
| 336 |
+
return token, "π Please login to continue."
|
| 337 |
+
|
| 338 |
+
# Bind the login event
|
| 339 |
+
login.success(
|
| 340 |
+
fn=handle_login,
|
| 341 |
+
inputs=[login],
|
| 342 |
+
outputs=[token_state, chatbot.chatbot_state]
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
if __name__ == "__main__":
|
| 346 |
demo.launch(
|
| 347 |
show_api=False,
|
| 348 |
share=False,
|
| 349 |
+
server_name="0.0.0.0",
|
| 350 |
+
server_port=7860
|
| 351 |
)
|