Files changed (1) hide show
  1. app.py +51 -19
app.py CHANGED
@@ -3,7 +3,10 @@ import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
  MODEL_ID = "MiniMaxAI/MiniMax-M2.5"
6
- SYSTEM_PROMPT = "You are a helpful assistant. Your name is MiniMax-M2.5 and is built by MiniMax."
 
 
 
7
 
8
  client = InferenceClient(
9
  provider="novita",
@@ -14,11 +17,14 @@ client = InferenceClient(
14
  def respond(message, history, system_message, max_tokens, temperature, top_p):
15
  messages = [{"role": "system", "content": system_message}]
16
 
17
- for user_msg, assistant_msg in history:
18
- if user_msg:
19
- messages.append({"role": "user", "content": user_msg})
20
- if assistant_msg:
21
- messages.append({"role": "assistant", "content": assistant_msg})
 
 
 
22
 
23
  messages.append({"role": "user", "content": message})
24
 
@@ -26,28 +32,53 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
26
  for chunk in client.chat_completion(
27
  model=MODEL_ID,
28
  messages=messages,
29
- max_tokens=max_tokens,
 
 
30
  stream=True,
31
- temperature=temperature,
32
- top_p=top_p,
33
  ):
34
- if chunk.choices and chunk.choices[0].delta.content:
35
- response += chunk.choices[0].delta.content
36
- yield response
 
 
37
 
38
 
39
  demo = gr.ChatInterface(
40
- respond,
 
41
  title="MiniMax M2.5 Chat",
42
  description=(
43
- "Chat with [MiniMax M2.5](https://huggingface.co/MiniMaxAI/MiniMax-M2.5) — "
44
- "a 230B MoE model (10B active) that is SOTA in coding, agentic tool use, and more."
 
45
  ),
46
  additional_inputs=[
47
- gr.Textbox(value=SYSTEM_PROMPT, label="System message"),
48
- gr.Slider(minimum=1, maximum=4096, value=2048, step=1, label="Max new tokens"),
49
- gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.05, label="Temperature"),
50
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  ],
52
  examples=[
53
  ["Write a Python function to check if a number is prime."],
@@ -57,5 +88,6 @@ demo = gr.ChatInterface(
57
  cache_examples=False,
58
  )
59
 
 
60
  if __name__ == "__main__":
61
  demo.launch()
 
3
  from huggingface_hub import InferenceClient
4
 
5
  MODEL_ID = "MiniMaxAI/MiniMax-M2.5"
6
+ SYSTEM_PROMPT = (
7
+ "You are a helpful assistant. "
8
+ "Your name is MiniMax-M2.5 and is built by MiniMax."
9
+ )
10
 
11
  client = InferenceClient(
12
  provider="novita",
 
17
  def respond(message, history, system_message, max_tokens, temperature, top_p):
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
+ # history در نسخه‌های جدید Gradio به صورت لیست دیکشنری است
21
+ for msg in history:
22
+ messages.append(
23
+ {
24
+ "role": msg["role"],
25
+ "content": msg["content"],
26
+ }
27
+ )
28
 
29
  messages.append({"role": "user", "content": message})
30
 
 
32
  for chunk in client.chat_completion(
33
  model=MODEL_ID,
34
  messages=messages,
35
+ max_tokens=int(max_tokens),
36
+ temperature=float(temperature),
37
+ top_p=float(top_p),
38
  stream=True,
 
 
39
  ):
40
+ if chunk.choices:
41
+ delta = chunk.choices[0].delta
42
+ if delta and delta.content:
43
+ response += delta.content
44
+ yield response
45
 
46
 
47
  demo = gr.ChatInterface(
48
+ fn=respond,
49
+ type="messages", # مهم
50
  title="MiniMax M2.5 Chat",
51
  description=(
52
+ "Chat with MiniMax M2.5 — "
53
+ "a 230B MoE model (10B active) that is SOTA in coding, "
54
+ "agentic tool use, and more."
55
  ),
56
  additional_inputs=[
57
+ gr.Textbox(
58
+ value=SYSTEM_PROMPT,
59
+ label="System message",
60
+ ),
61
+ gr.Slider(
62
+ minimum=1,
63
+ maximum=4096,
64
+ value=2048,
65
+ step=1,
66
+ label="Max new tokens",
67
+ ),
68
+ gr.Slider(
69
+ minimum=0.1,
70
+ maximum=2.0,
71
+ value=1.0,
72
+ step=0.05,
73
+ label="Temperature",
74
+ ),
75
+ gr.Slider(
76
+ minimum=0.1,
77
+ maximum=1.0,
78
+ value=0.95,
79
+ step=0.05,
80
+ label="Top-p",
81
+ ),
82
  ],
83
  examples=[
84
  ["Write a Python function to check if a number is prime."],
 
88
  cache_examples=False,
89
  )
90
 
91
+
92
  if __name__ == "__main__":
93
  demo.launch()