dinhquangson commited on
Commit
6c900c2
1 Parent(s): 3de72c6

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
3
+
4
+ model_path = "vinai/PhoGPT-7B5-Instruct"
5
+
6
+ config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
7
+ config.init_device = "cuda"
8
+ # config.attn_config['attn_impl'] = 'triton' # Enable if "triton" installed!
9
+
10
+ model = AutoModelForCausalLM.from_pretrained(
11
+ model_path, config=config, torch_dtype=torch.bfloat16, trust_remote_code=True
12
+ )
13
+ # If your GPU does not support bfloat16:
14
+ # model = AutoModelForCausalLM.from_pretrained(model_path, config=config, torch_dtype=torch.float16, trust_remote_code=True)
15
+ model.eval()
16
+
17
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
18
+
19
+
20
+ def answer(input_prompt):
21
+ input_ids = tokenizer(input_prompt, return_tensors="pt")
22
+
23
+ outputs = model.generate(
24
+ inputs=input_ids["input_ids"].to("cuda"),
25
+ attention_mask=input_ids["attention_mask"].to("cuda"),
26
+ do_sample=True,
27
+ temperature=1.0,
28
+ top_k=50,
29
+ top_p=0.9,
30
+ max_new_tokens=1024,
31
+ eos_token_id=tokenizer.eos_token_id,
32
+ pad_token_id=tokenizer.pad_token_id
33
+ )
34
+
35
+ response = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
36
+ response = response.split("### Trả lời:")[1]
37
+ return response
38
+
39
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
40
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio