Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,10 +6,10 @@ import os
|
|
| 6 |
# ============================================
|
| 7 |
# MiniMax-M2.1 Streaming Chat
|
| 8 |
# Dual Provider: Novita (HF) + MiniMax Official API
|
| 9 |
-
# Gradio 6.0 Compatible
|
| 10 |
# ============================================
|
| 11 |
|
| 12 |
-
# Provider
|
| 13 |
class ProviderManager:
|
| 14 |
def __init__(self):
|
| 15 |
self.current_provider = "novita"
|
|
@@ -47,7 +47,7 @@ class ProviderManager:
|
|
| 47 |
provider = ProviderManager()
|
| 48 |
|
| 49 |
def chat_with_novita(messages):
|
| 50 |
-
"""Novita provider
|
| 51 |
stream = provider.novita_client.chat.completions.create(
|
| 52 |
model="MiniMaxAI/MiniMax-M2.1",
|
| 53 |
messages=messages,
|
|
@@ -62,7 +62,7 @@ def chat_with_novita(messages):
|
|
| 62 |
yield chunk.choices[0].delta.content
|
| 63 |
|
| 64 |
def chat_with_minimax(messages):
|
| 65 |
-
"""MiniMax
|
| 66 |
stream = provider.minimax_client.chat.completions.create(
|
| 67 |
model="MiniMax-M2.1",
|
| 68 |
messages=messages,
|
|
@@ -99,12 +99,11 @@ def chat_respond(message, history):
|
|
| 99 |
|
| 100 |
response_text = ""
|
| 101 |
|
| 102 |
-
#
|
| 103 |
if provider.novita_available and provider.current_provider == "novita":
|
| 104 |
try:
|
| 105 |
for chunk in chat_with_novita(api_messages):
|
| 106 |
response_text += chunk
|
| 107 |
-
# Gradio 6.0 messages format
|
| 108 |
new_history = history + [
|
| 109 |
{"role": "user", "content": message},
|
| 110 |
{"role": "assistant", "content": response_text}
|
|
@@ -119,7 +118,7 @@ def chat_respond(message, history):
|
|
| 119 |
else:
|
| 120 |
print(f"β οΈ Novita error: {e}")
|
| 121 |
|
| 122 |
-
#
|
| 123 |
try:
|
| 124 |
if not os.environ.get("MINIMAX_API_KEY"):
|
| 125 |
new_history = history + [
|
|
@@ -148,12 +147,12 @@ def chat_respond(message, history):
|
|
| 148 |
yield new_history, "π΄ Error"
|
| 149 |
|
| 150 |
def reset_provider_fn():
|
| 151 |
-
"""
|
| 152 |
provider.reset_to_novita()
|
| 153 |
return "β
Reset to Novita!"
|
| 154 |
|
| 155 |
def clear_chat_fn():
|
| 156 |
-
"""
|
| 157 |
return [], "", provider.get_status()
|
| 158 |
|
| 159 |
# ============================================
|
|
@@ -261,13 +260,6 @@ textarea:focus, input[type="text"]:focus {
|
|
| 261 |
box-shadow: 4px 4px 0px #10B981 !important;
|
| 262 |
}
|
| 263 |
|
| 264 |
-
.gr-accordion {
|
| 265 |
-
background: #FACC15 !important;
|
| 266 |
-
border: 3px solid #1F2937 !important;
|
| 267 |
-
border-radius: 8px !important;
|
| 268 |
-
box-shadow: 4px 4px 0px #1F2937 !important;
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
.chatbot {
|
| 272 |
border: 3px solid #1F2937 !important;
|
| 273 |
border-radius: 12px !important;
|
|
@@ -294,7 +286,7 @@ pre, code {
|
|
| 294 |
"""
|
| 295 |
|
| 296 |
# ============================================
|
| 297 |
-
# Gradio Interface
|
| 298 |
# ============================================
|
| 299 |
with gr.Blocks(fill_height=True) as demo:
|
| 300 |
|
|
@@ -315,11 +307,11 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 315 |
|
| 316 |
# Header Title
|
| 317 |
gr.Markdown("""# π€ MINIMAX-M2.1 CHAT π¬""", elem_classes="header-text")
|
| 318 |
-
gr.Markdown("""<p class="subtitle">β‘ Claude Sonnet 4.5
|
| 319 |
|
| 320 |
# Model Info Box
|
| 321 |
gr.HTML("""
|
| 322 |
-
<div style="background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%); border: 3px solid #1F2937; border-radius: 12px; padding: 15px; color: white; box-shadow: 5px 5px 0px #1F2937; margin: 0 auto 20px auto; max-width:
|
| 323 |
<div style="display: flex; justify-content: space-around; flex-wrap: wrap; text-align: center;">
|
| 324 |
<div><strong style="font-size: 1.5rem;">230B</strong><br><span style="font-size: 0.9rem;">Total Params</span></div>
|
| 325 |
<div><strong style="font-size: 1.5rem;">10B</strong><br><span style="font-size: 0.9rem;">Active Params</span></div>
|
|
@@ -329,84 +321,37 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 329 |
</div>
|
| 330 |
""")
|
| 331 |
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
# Clear Button
|
| 365 |
-
clear_btn = gr.Button("ποΈ CLEAR CHAT", variant="secondary")
|
| 366 |
-
|
| 367 |
-
# Right Column - Info
|
| 368 |
-
with gr.Column(scale=1, min_width=300):
|
| 369 |
-
with gr.Accordion("π‘ Example Prompts", open=True):
|
| 370 |
-
gr.Markdown("""
|
| 371 |
-
**μ½λ©:**
|
| 372 |
-
- PythonμΌλ‘ ν΅μνΈ κ΅¬νν΄μ€
|
| 373 |
-
- React Todo μ± λ§λ€μ΄μ€
|
| 374 |
-
- FastAPI JWT μΈμ¦ ꡬνν΄μ€
|
| 375 |
-
|
| 376 |
-
**μ€λͺ
:**
|
| 377 |
-
- Docker vs Kubernetes μ°¨μ΄μ
|
| 378 |
-
- REST API μ€κ³ λ² μ€νΈ νλν°μ€
|
| 379 |
-
|
| 380 |
-
**λΆμ:**
|
| 381 |
-
- λ¨Έμ λ¬λ λ°°ν¬ νμ΄νλΌμΈ μ€κ³
|
| 382 |
-
""")
|
| 383 |
-
|
| 384 |
-
with gr.Accordion("π Provider Info", open=False):
|
| 385 |
-
gr.Markdown("""
|
| 386 |
-
### λμΌ νλ‘λ°μ΄λ
|
| 387 |
-
|
| 388 |
-
**1μ°¨: Novita (HuggingFace)**
|
| 389 |
-
- HF PRO ν¬λ λ§ μ¬μ©
|
| 390 |
-
|
| 391 |
-
**2μ°¨: MiniMax Official API**
|
| 392 |
-
- ν¬λ λ§ μμ§ μ μλ μ ν
|
| 393 |
-
- νμ¬ νμμ 무λ£
|
| 394 |
-
|
| 395 |
-
### Secrets μ€μ
|
| 396 |
-
```
|
| 397 |
-
HF_TOKEN
|
| 398 |
-
MINIMAX_API_KEY
|
| 399 |
-
```
|
| 400 |
-
""")
|
| 401 |
-
|
| 402 |
-
with gr.Accordion("π― Model Info", open=False):
|
| 403 |
-
gr.Markdown("""
|
| 404 |
-
- **π SOTA μ½λ©** β Claude Sonnet 4.5 λ₯κ°
|
| 405 |
-
- **π λ€κ΅μ΄** β Python, Rust, Java, Go, C++
|
| 406 |
-
- **π€ μμ΄μ νΈ** β λ©ν°μ€ν
νμ€ν¬
|
| 407 |
-
- **π‘ μΆλ‘ ** β Interleaved Thinking
|
| 408 |
-
- **π§ λꡬ** β ν¨μ νΈμΆ μ§μ
|
| 409 |
-
""")
|
| 410 |
|
| 411 |
# Event Handlers
|
| 412 |
def respond(message, history):
|
|
|
|
| 6 |
# ============================================
|
| 7 |
# MiniMax-M2.1 Streaming Chat
|
| 8 |
# Dual Provider: Novita (HF) + MiniMax Official API
|
| 9 |
+
# Gradio 6.0 Compatible - Full Width Layout
|
| 10 |
# ============================================
|
| 11 |
|
| 12 |
+
# Provider Management
|
| 13 |
class ProviderManager:
|
| 14 |
def __init__(self):
|
| 15 |
self.current_provider = "novita"
|
|
|
|
| 47 |
provider = ProviderManager()
|
| 48 |
|
| 49 |
def chat_with_novita(messages):
|
| 50 |
+
"""Streaming via Novita provider"""
|
| 51 |
stream = provider.novita_client.chat.completions.create(
|
| 52 |
model="MiniMaxAI/MiniMax-M2.1",
|
| 53 |
messages=messages,
|
|
|
|
| 62 |
yield chunk.choices[0].delta.content
|
| 63 |
|
| 64 |
def chat_with_minimax(messages):
|
| 65 |
+
"""Streaming via MiniMax Official API"""
|
| 66 |
stream = provider.minimax_client.chat.completions.create(
|
| 67 |
model="MiniMax-M2.1",
|
| 68 |
messages=messages,
|
|
|
|
| 99 |
|
| 100 |
response_text = ""
|
| 101 |
|
| 102 |
+
# 1st: Try Novita
|
| 103 |
if provider.novita_available and provider.current_provider == "novita":
|
| 104 |
try:
|
| 105 |
for chunk in chat_with_novita(api_messages):
|
| 106 |
response_text += chunk
|
|
|
|
| 107 |
new_history = history + [
|
| 108 |
{"role": "user", "content": message},
|
| 109 |
{"role": "assistant", "content": response_text}
|
|
|
|
| 118 |
else:
|
| 119 |
print(f"β οΈ Novita error: {e}")
|
| 120 |
|
| 121 |
+
# 2nd: Fallback to MiniMax
|
| 122 |
try:
|
| 123 |
if not os.environ.get("MINIMAX_API_KEY"):
|
| 124 |
new_history = history + [
|
|
|
|
| 147 |
yield new_history, "π΄ Error"
|
| 148 |
|
| 149 |
def reset_provider_fn():
|
| 150 |
+
"""Manually reset to Novita"""
|
| 151 |
provider.reset_to_novita()
|
| 152 |
return "β
Reset to Novita!"
|
| 153 |
|
| 154 |
def clear_chat_fn():
|
| 155 |
+
"""Clear chat history"""
|
| 156 |
return [], "", provider.get_status()
|
| 157 |
|
| 158 |
# ============================================
|
|
|
|
| 260 |
box-shadow: 4px 4px 0px #10B981 !important;
|
| 261 |
}
|
| 262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
.chatbot {
|
| 264 |
border: 3px solid #1F2937 !important;
|
| 265 |
border-radius: 12px !important;
|
|
|
|
| 286 |
"""
|
| 287 |
|
| 288 |
# ============================================
|
| 289 |
+
# Gradio Interface - Full Width Layout (English)
|
| 290 |
# ============================================
|
| 291 |
with gr.Blocks(fill_height=True) as demo:
|
| 292 |
|
|
|
|
| 307 |
|
| 308 |
# Header Title
|
| 309 |
gr.Markdown("""# π€ MINIMAX-M2.1 CHAT π¬""", elem_classes="header-text")
|
| 310 |
+
gr.Markdown("""<p class="subtitle">β‘ Claude Sonnet 4.5-level Coding & Agent Performance! 230B Parameter Open Source Model π</p>""")
|
| 311 |
|
| 312 |
# Model Info Box
|
| 313 |
gr.HTML("""
|
| 314 |
+
<div style="background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%); border: 3px solid #1F2937; border-radius: 12px; padding: 15px; color: white; box-shadow: 5px 5px 0px #1F2937; margin: 0 auto 20px auto; max-width: 1200px;">
|
| 315 |
<div style="display: flex; justify-content: space-around; flex-wrap: wrap; text-align: center;">
|
| 316 |
<div><strong style="font-size: 1.5rem;">230B</strong><br><span style="font-size: 0.9rem;">Total Params</span></div>
|
| 317 |
<div><strong style="font-size: 1.5rem;">10B</strong><br><span style="font-size: 0.9rem;">Active Params</span></div>
|
|
|
|
| 321 |
</div>
|
| 322 |
""")
|
| 323 |
|
| 324 |
+
# Provider Status Row
|
| 325 |
+
with gr.Row():
|
| 326 |
+
provider_status = gr.Textbox(
|
| 327 |
+
value="π’ Novita (HuggingFace)",
|
| 328 |
+
label="π Current Provider",
|
| 329 |
+
interactive=False,
|
| 330 |
+
elem_classes="status-box",
|
| 331 |
+
scale=4
|
| 332 |
+
)
|
| 333 |
+
reset_btn = gr.Button("π Reset Provider", variant="secondary", scale=1)
|
| 334 |
+
|
| 335 |
+
# Chatbot - Full Width
|
| 336 |
+
chatbot = gr.Chatbot(
|
| 337 |
+
label="π¬ Chat",
|
| 338 |
+
height=500,
|
| 339 |
+
show_label=False,
|
| 340 |
+
elem_classes="chatbot"
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
# Input Row
|
| 344 |
+
with gr.Row():
|
| 345 |
+
msg = gr.Textbox(
|
| 346 |
+
label="",
|
| 347 |
+
placeholder="Enter your message... (coding, analysis, creative writing, anything!)",
|
| 348 |
+
scale=8,
|
| 349 |
+
container=False
|
| 350 |
+
)
|
| 351 |
+
submit_btn = gr.Button("π€ SEND", variant="primary", scale=2)
|
| 352 |
+
|
| 353 |
+
# Clear Button
|
| 354 |
+
clear_btn = gr.Button("ποΈ CLEAR CHAT", variant="secondary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
|
| 356 |
# Event Handlers
|
| 357 |
def respond(message, history):
|