PraveshS commited on
Commit
0eafd6b
1 Parent(s): 9dc140a

app py created

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ model_path = "core42/jais-13b"
4
+
5
+ device = "cuda" if torch.cuda.is_available() else "cpu"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
8
+ model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto", trust_remote_code=True)
9
+
10
+
11
+ def get_response(text,tokenizer=tokenizer,model=model):
12
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
13
+ inputs = input_ids.to(device)
14
+ input_len = inputs.shape[-1]
15
+ generate_ids = model.generate(
16
+ inputs,
17
+ top_p=0.9,
18
+ temperature=0.3,
19
+ max_length=200-input_len,
20
+ min_length=input_len + 4,
21
+ repetition_penalty=1.2,
22
+ do_sample=True,
23
+ )
24
+ response = tokenizer.batch_decode(
25
+ generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
26
+ )[0]
27
+ return response
28
+
29
+
30
+ text= "عاصمة دولة الإمارات العربية المتحدة ه"
31
+ print(get_response(text))
32
+
33
+ text = "The capital of UAE is"
34
+ print(get_response(text))