ostarling commited on
Commit
efd464a
·
verified ·
1 Parent(s): 79bbca6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ MODEL_ID = "MiniMaxAI/MiniMax-M2.5"
5
+ SYSTEM_PROMPT = "You are a helpful assistant. Your name is MiniMax-M2.5 and is built by MiniMax."
6
+
7
+ client = InferenceClient(MODEL_ID)
8
+
9
+
10
+ def respond(message, history, system_message, max_tokens, temperature, top_p):
11
+ messages = [{"role": "system", "content": system_message}]
12
+
13
+ for user_msg, assistant_msg in history:
14
+ if user_msg:
15
+ messages.append({"role": "user", "content": user_msg})
16
+ if assistant_msg:
17
+ messages.append({"role": "assistant", "content": assistant_msg})
18
+
19
+ messages.append({"role": "user", "content": message})
20
+
21
+ response = ""
22
+ for chunk in client.chat_completion(
23
+ messages,
24
+ max_tokens=max_tokens,
25
+ stream=True,
26
+ temperature=temperature,
27
+ top_p=top_p,
28
+ ):
29
+ token = chunk.choices[0].delta.content
30
+ if token:
31
+ response += token
32
+ yield response
33
+
34
+
35
+ demo = gr.ChatInterface(
36
+ respond,
37
+ title="MiniMax M2.5 Chat",
38
+ description=(
39
+ "Chat with [MiniMax M2.5](https://huggingface.co/MiniMaxAI/MiniMax-M2.5) — "
40
+ "a 230B MoE model (10B active) that is SOTA in coding, agentic tool use, and more."
41
+ ),
42
+ additional_inputs=[
43
+ gr.Textbox(value=SYSTEM_PROMPT, label="System message"),
44
+ gr.Slider(minimum=1, maximum=4096, value=2048, step=1, label="Max new tokens"),
45
+ gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.05, label="Temperature"),
46
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
47
+ ],
48
+ examples=[
49
+ ["Write a Python function to check if a number is prime."],
50
+ ["Explain the difference between TCP and UDP in simple terms."],
51
+ ["Help me write a bash script that monitors disk usage and sends an alert."],
52
+ ],
53
+ cache_examples=False,
54
+ )
55
+
56
+ if __name__ == "__main__":
57
+ demo.launch()