seawolf2357 commited on
Commit
5252fc3
Β·
verified Β·
1 Parent(s): 1df496d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -97
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 곡식 APIλ₯Ό ν†΅ν•œ 슀트리밍"""
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
- # 1μ°¨: 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
- # 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
- # 2μ°¨: MiniMax
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
- """μˆ˜λ™μœΌλ‘œ Novita둜 리셋"""
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 (Gradio 6.0 Compatible)
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 μˆ˜μ€€μ˜ μ½”λ”© & μ—μ΄μ „νŠΈ μ„±λŠ₯! 230B νŒŒλΌλ―Έν„° μ˜€ν”ˆμ†ŒμŠ€ λͺ¨λΈ πŸš€</p>""")
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: 800px;">
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
- with gr.Row(equal_height=False):
333
- # Left Column - Chat
334
- with gr.Column(scale=2, min_width=400):
335
- # Provider Status
336
- with gr.Row():
337
- provider_status = gr.Textbox(
338
- value="🟒 Novita (HuggingFace)",
339
- label="πŸ”Œ Current Provider",
340
- interactive=False,
341
- elem_classes="status-box",
342
- scale=3
343
- )
344
- reset_btn = gr.Button("πŸ”„ Reset", variant="secondary", scale=1)
345
-
346
- # Chatbot - Gradio 6.0 uses messages format by default
347
- chatbot = gr.Chatbot(
348
- label="πŸ’¬ Chat",
349
- height=450,
350
- show_label=False,
351
- elem_classes="chatbot"
352
- )
353
-
354
- # Input Row
355
- with gr.Row():
356
- msg = gr.Textbox(
357
- label="",
358
- placeholder="λ©”μ‹œμ§€λ₯Ό μž…λ ₯ν•˜μ„Έμš”... (μ½”λ”©, 뢄석, μ°½μž‘ λ“± 무엇이든!)",
359
- scale=8,
360
- container=False
361
- )
362
- submit_btn = gr.Button("πŸ“€ SEND", variant="primary", scale=2)
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):