TharunSivamani commited on
Commit
65fe553
1 Parent(s): 61d0f76
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -1,24 +1,13 @@
1
  import gradio as gr
2
  import torch
3
- from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline,BitsAndBytesConfig
4
-
5
- #model = AutoModelForCausalLM.from_pretrained("checkpoint_500",trust_remote_code=True)
6
-
7
- model_name = "microsoft/phi-2"
8
-
9
  import os
10
  token = os.environ.get("HUGGING_FACE_TOKEN")
11
 
12
-
13
- #bnb_config = BitsAndBytesConfig(
14
- # load_in_4bit=True,
15
- # bnb_4bit_quant_type="nf4",
16
- # bnb_4bit_compute_dtype=torch.float16,
17
- #)
18
 
19
  model = AutoModelForCausalLM.from_pretrained(
20
  model_name,
21
- #quantization_config=bnb_config,
22
  use_auth_token=token,
23
  trust_remote_code=True
24
  )
@@ -28,25 +17,28 @@ model.load_adapter("checkpoint_500")
28
  tokenizer = AutoTokenizer.from_pretrained("checkpoint_500", trust_remote_code=True)
29
  tokenizer.pad_token = tokenizer.eos_token
30
 
 
31
  def inference(prompt, count):
32
  count = int(count)
33
  pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer)
34
  result = pipe(f"{prompt}",max_new_tokens=count)
35
- out_text = result[0]['generated_text']
36
- return out_text
37
 
38
- title = "TSAI S21 Assignment: Adaptive QLoRA training on open assist oasst1 dataset, using microsoft/phi2 model"
39
- description = "A simple Gradio interface that accepts a context and generates GPT like text "
40
- examples = [["What is a large language model?","50"]
41
- ]
42
-
43
 
44
  demo = gr.Interface(
45
  inference,
46
- inputs = [gr.Textbox(placeholder="Enter a prompt"), gr.Textbox(placeholder="Enter number of characters you want to generate")],
47
- outputs = [gr.Textbox(label="Chat GPT like text")],
48
- title = title,
49
- description = description,
 
 
 
50
  examples = examples
51
  )
 
52
  demo.launch()
 
1
  import gradio as gr
2
  import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
 
 
 
 
 
4
  import os
5
  token = os.environ.get("HUGGING_FACE_TOKEN")
6
 
7
+ model_name = "microsoft/phi-2"
 
 
 
 
 
8
 
9
  model = AutoModelForCausalLM.from_pretrained(
10
  model_name,
 
11
  use_auth_token=token,
12
  trust_remote_code=True
13
  )
 
17
  tokenizer = AutoTokenizer.from_pretrained("checkpoint_500", trust_remote_code=True)
18
  tokenizer.pad_token = tokenizer.eos_token
19
 
20
+
21
  def inference(prompt, count):
22
  count = int(count)
23
  pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer)
24
  result = pipe(f"{prompt}",max_new_tokens=count)
25
+ output = result[0]['generated_text']
26
+ return output
27
 
28
+ examples = [
29
+ ["What is LLM?","50"]
30
+ ]
 
 
31
 
32
  demo = gr.Interface(
33
  inference,
34
+ inputs = [
35
+ gr.Textbox(placeholder="Enter a prompt"),
36
+ gr.Textbox(placeholder="Enter number of characters you want to generate")
37
+ ],
38
+ outputs = [
39
+ gr.Textbox(label="Generated text")
40
+ ],
41
  examples = examples
42
  )
43
+
44
  demo.launch()