Chintan-Shah commited on
Commit
1ad8e33
1 Parent(s): 9bb690a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline
3
+
4
+ import time
5
+ import gradio as gr
6
+
7
+ bnb_config = BitsAndBytesConfig(
8
+ load_in_4bit=True,
9
+ bnb_4bit_quant_type="nf4",
10
+ bnb_4bit_compute_dtype=torch.bfloat16,
11
+ )
12
+
13
+ model = AutoModelForCausalLM.from_pretrained(
14
+ "microsoft/Phi-3.5-mini-instruct",
15
+ torch_dtype=torch.bfloat16,
16
+ quantization_config=bnb_config,
17
+ trust_remote_code=True
18
+ )
19
+ model.load_adapter('./finetunedPEFTModel')
20
+
21
+ tokenizer = AutoTokenizer.from_pretrained('./finetunedPEFTModel', trust_remote_code=True)
22
+ # tokenizer.pad_token = tokenizer.unk_token
23
+ # tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3.5-mini-instruct", trust_remote_code=True)
24
+
25
+
26
+ def generateText(inputText="JULIET\n", num_tokens=200):
27
+
28
+ # pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=num_tokens)
29
+ # result = pipe(f'''[INST] {inputText} [/INST]''')
30
+ # print(result[0]['generated_text'])
31
+
32
+ prompt = "What is model regularization?"
33
+ pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=num_tokens)
34
+ result = pipe(f'''{inputText}''')
35
+
36
+ return result[0]['generated_text']
37
+
38
+
39
+ title = "Fine tuned Phi3.5 instruct model on OpenAssist dataset using QLora"
40
+ description = "Fine tuned Phi3.5 instruct model on OpenAssist dataset using QLora"
41
+ examples = [
42
+ ["How can I optimize my web page for online search so that it is on top?", 200],
43
+ ["Can you give me an example of python script for Fibonacci series?", 200],
44
+ ["Can you explain what is Contrastive Loss in Deep Learning?", 200],
45
+ ["How are Sentence Transformers different from Huggingface Transformers?", 200],
46
+ ]
47
+
48
+ demo = gr.Interface(
49
+ generateText,
50
+ inputs = [
51
+ gr.Textbox(label="Question that you want to ask"),
52
+ gr.Slider(100, 500, value = 200, step=100, label="Number of chars that you want in your output"),
53
+ ],
54
+ outputs = [
55
+ gr.Text(),
56
+ ],
57
+ title = title,
58
+ description = description,
59
+ examples = examples,
60
+ cache_examples=False
61
+ )
62
+ demo.launch()