bts696969 commited on
Commit
0fb704d
·
verified ·
1 Parent(s): 3911903

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ model_name = "dphn/Dolphin3.0-Llama3.1-8B"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(
9
+ model_name,
10
+ torch_dtype=torch.float16,
11
+ device_map="auto"
12
+ )
13
+
14
+ def chat(message, history):
15
+ inputs = tokenizer.apply_chat_template(
16
+ history + [{"role": "user", "content": message}],
17
+ return_tensors="pt"
18
+ ).to(model.device)
19
+ outputs = model.generate(inputs, max_new_tokens=512)
20
+ reply = tokenizer.decode(outputs[0], skip_special_tokens=True)
21
+ history.append({"role": "assistant", "content": reply})
22
+ return reply, history
23
+
24
+ gr.ChatInterface(fn=chat, title="Dolphin 3.0 Chat").launch()