SohamNale commited on
Commit
ac003a6
β€’
1 Parent(s): 18974c9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from peft import PeftModel
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ import transformers
5
+ adapters_name = "SohamNale/Soham_Misteral"
6
+ model_name = "anakin87/zephyr-7b-alpha-sharded"
7
+
8
+ device = "cuda" # the device to load the model onto
9
+
10
+ bnb_config = transformers.BitsAndBytesConfig(
11
+ load_in_4bit=True,
12
+ bnb_4bit_use_double_quant=True,
13
+ bnb_4bit_quant_type="nf4",
14
+ bnb_4bit_compute_dtype=torch.bfloat16
15
+ )
16
+
17
+ model = AutoModelForCausalLM.from_pretrained(
18
+ model_name,
19
+ load_in_4bit=True,
20
+ torch_dtype=torch.bfloat16,
21
+ quantization_config=bnb_config,
22
+ device_map='auto'
23
+ )
24
+
25
+ model = PeftModel.from_pretrained(model, adapters_name)
26
+
27
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
28
+ tokenizer.bos_token_id = 1
29
+
30
+ stop_token_ids = [0]
31
+
32
+ print(f"Successfully loaded the model {model_name} into memory")
33
+
34
+ import gradio as gr
35
+
36
+ def ui(text):
37
+ device = "cuda:0"
38
+
39
+ inputs = tokenizer(text, return_tensors="pt").to(device)
40
+ outputs = model.generate(**inputs, max_new_tokens=500)
41
+ return(tokenizer.decode(outputs[0], skip_special_tokens=True))
42
+
43
+ demo = gr.Interface(fn=ui, inputs="text", outputs="text", title="Banking Query Assistant", description="Enter the query prompt for which you require assistance")
44
+
45
+ demo.launch(inline = False)