lucas-w commited on
Commit
81c4ebe
β€’
1 Parent(s): bcad892

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -3
app.py CHANGED
@@ -17,6 +17,8 @@ demo.launch()
17
  #!pip install accelerate
18
  #!pip install -i
19
 
 
 
20
  import gradio as gr
21
  import torch
22
  from peft import PeftModel, PeftConfig
@@ -40,8 +42,8 @@ newmodel = PeftModel.from_pretrained(newmodel, peft_model_id,
40
  use_auth_token="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", load_in_8bit=True, device_map='auto')
41
 
42
  def givetext(input_text,lmodel,ltokenizer):
43
- eval_prompt_pt1 = """\nBelow is an instruction that describes a task. Write a response that appropriately completes the request.\n### Instruction: Act like a therapist and respond\n\n### Input: """
44
- eval_prompt_pt2="""\n\n\n### Response:\n"""
45
  eval_prompt=eval_prompt_pt1+input_text+eval_prompt_pt2
46
  print(eval_prompt,"\n\n")
47
  model_input = ltokenizer(eval_prompt, return_tensors="pt").to("cuda")
@@ -56,4 +58,37 @@ def mental_chat(message, history):
56
 
57
  demo = gr.ChatInterface(mental_chat)
58
 
59
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  #!pip install accelerate
18
  #!pip install -i
19
 
20
+ """
21
+
22
  import gradio as gr
23
  import torch
24
  from peft import PeftModel, PeftConfig
 
42
  use_auth_token="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", load_in_8bit=True, device_map='auto')
43
 
44
  def givetext(input_text,lmodel,ltokenizer):
45
+ eval_prompt_pt1 = "\nBelow is an instruction that describes a task. Write a response that appropriately completes the request.\n### Instruction: Act like a therapist and respond\n\n### Input: "
46
+ eval_prompt_pt2="\n\n\n### Response:\n"
47
  eval_prompt=eval_prompt_pt1+input_text+eval_prompt_pt2
48
  print(eval_prompt,"\n\n")
49
  model_input = ltokenizer(eval_prompt, return_tensors="pt").to("cuda")
 
58
 
59
  demo = gr.ChatInterface(mental_chat)
60
 
61
+ demo.launch()
62
+
63
+ """
64
+
65
+
66
+ import gradio as gr
67
+ import torch
68
+ from peft import PeftModel, PeftConfig
69
+ from transformers import AutoModelForCausalLM, AutoTokenizer
70
+
71
+ peft_model_id = "charansr/llama2-7b-chat-hf-therapist"
72
+
73
+ # Load the Lora model
74
+ newmodel = PeftModel.from_pretrained(peft_model_id, use_auth_token="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")
75
+
76
+ newtokenizer = AutoTokenizer.from_pretrained(peft_model_id, use_auth_token="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")
77
+
78
+ def givetext(input_text, lmodel, ltokenizer):
79
+ eval_prompt_pt1 = """\nBelow is an instruction that describes a task. Write a response that appropriately completes the request.\n### Instruction: Act like a therapist and respond\n\n### Input: """
80
+ eval_prompt_pt2 = """\n\n\n### Response:\n"""
81
+ eval_prompt = eval_prompt_pt1 + input_text + eval_prompt_pt2
82
+ print(eval_prompt, "\n\n")
83
+ model_input = ltokenizer(eval_prompt, return_tensors="pt").to("cuda")
84
+
85
+ lmodel.eval()
86
+ with torch.no_grad():
87
+ return ltokenizer.decode(lmodel.generate(**model_input, max_new_tokens=1000)[0], skip_special_tokens=True)
88
+
89
+ def mental_chat(message, history):
90
+ return givetext(message, newmodel, newtokenizer)
91
+
92
+ demo = gr.ChatInterface(mental_chat)
93
+
94
+ demo.launch()