lucas-w commited on
Commit
28d9ec7
β€’
1 Parent(s): 7ad2c82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
 
3
  def mental_chat(message, history):
@@ -5,4 +6,32 @@ def mental_chat(message, history):
5
 
6
  demo = gr.ChatInterface(mental_chat)
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  demo.launch()
 
1
+ """
2
  import gradio as gr
3
 
4
  def mental_chat(message, history):
 
6
 
7
  demo = gr.ChatInterface(mental_chat)
8
 
9
+ demo.launch()
10
+ """
11
+
12
+ peft_model_id = "charansr/llama2-7b-chat-hf-therapist"
13
+ config = PeftConfig.from_pretrained(peft_model_id)
14
+ newmodel = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=True, device_map='auto')
15
+ newtokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
16
+
17
+ # Load the Lora model
18
+ newmodel = PeftModel.from_pretrained(newmodel, peft_model_id)
19
+
20
+ def givetext(input_text,lmodel,ltokenizer):
21
+ 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: """
22
+ eval_prompt_pt2="""\n\n\n### Response:\n"""
23
+ eval_prompt=eval_prompt_pt1+input_text+eval_prompt_pt2
24
+ print(eval_prompt,"\n\n")
25
+ model_input = ltokenizer(eval_prompt, return_tensors="pt").to("cuda")
26
+
27
+ lmodel.eval()
28
+ with torch.no_grad():
29
+ return (ltokenizer.decode(lmodel.generate(**model_input, max_new_tokens=1000)[0], skip_special_tokens=True))
30
+ #return (ltokenizer.decode(lmodel.generate(**model_input, max_new_tokens=100)[0], skip_special_tokens=True))
31
+
32
+ def mental_chat(message, history):
33
+ return givetext(patienttext,newmodel,newtokenizer)
34
+
35
+ demo = gr.ChatInterface(mental_chat)
36
+
37
  demo.launch()