akhaliq HF Staff commited on
Commit
d973e29
·
verified ·
1 Parent(s): 3044f91

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spaces
3
+ from transformers import pipeline
4
+ import torch
5
+
6
+ MODEL_ID = "LLM360/K2-Think"
7
+
8
+ pipe = pipeline(
9
+ "text-generation",
10
+ model=MODEL_ID,
11
+ torch_dtype="auto",
12
+ device_map="auto",
13
+ )
14
+
15
+ @spaces.GPU
16
+ def respond(message, history):
17
+ if history is None:
18
+ history = []
19
+ new_history = history + [{"role": "user", "content": message}]
20
+ outputs = pipe(
21
+ new_history,
22
+ max_new_tokens=32768,
23
+ )
24
+ response = outputs[0]["generated_text"][-1]["content"]
25
+ new_history.append({"role": "assistant", "content": response})
26
+ return "", new_history
27
+
28
+ with gr.Blocks(title="K2-Think Chat") as demo:
29
+ gr.Markdown("# K2-Think Chat App")
30
+ chatbot = gr.Chatbot(type="messages", height=500)
31
+ msg = gr.Textbox(placeholder="Type your message here...", scale=7)
32
+ clear_btn = gr.Button("Clear Chat")
33
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
34
+ clear_btn.click(lambda: None, None, chatbot, queue=False)
35
+
36
+ if __name__ == "__main__":
37
+ demo.launch()