Ronaldo commited on
Commit
58457ef
·
1 Parent(s): ee5808f

first commit

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ model_id = "LiquidAI/LFM2.5-1.2B-Instruct"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
7
+ model = AutoModelForCausalLM.from_pretrained(
8
+ model_id, device_map="auto", torch_dtype=torch.bfloat16
9
+ )
10
+
11
+ def chat(message, history):
12
+ messages = history + [{"role": "user", "content": message}]
13
+
14
+ input_ids = tokenizer.apply_chat_template(
15
+ messages, add_generation_prompt=True,
16
+ return_tensors="pt", tokenize=True
17
+ ).to(model.device)
18
+
19
+ output = model.generate(
20
+ input_ids, do_sample=True,
21
+ temperature=0.1, top_k=50,
22
+ repetition_penalty=1.05, max_new_tokens=512
23
+ )
24
+ return tokenizer.decode(output[0][input_ids.shape[1]:], skip_special_tokens=True)
25
+
26
+ demo = gr.ChatInterface(
27
+ fn=chat,
28
+ type="messages",
29
+ title="LFM2.5 Chat",
30
+ description="Chat avec le modèle LiquidAI LFM2.5-1.2B-Instruct",
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio>=4.0.0
2
+ transformers
3
+ torch
4
+ accelerate