Yesichen commited on
Commit
9efefc1
·
verified ·
1 Parent(s): f7f1c0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -26,7 +26,17 @@ model = PeftModel.from_pretrained(base, lora_adapter)
26
  model.eval()
27
 
28
  def chat(user_input, history):
29
- messages = [{"role": "user", "content": user_input}]
 
 
 
 
 
 
 
 
 
 
30
  input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
31
 
32
  with torch.no_grad():
@@ -43,6 +53,7 @@ def chat(user_input, history):
43
  history.append((user_input, response.strip()))
44
  return history, history
45
 
 
46
  gr.Interface(
47
  fn=chat,
48
  inputs=[gr.Textbox(placeholder="Tell me how you feel..."), gr.State([])],
 
26
  model.eval()
27
 
28
  def chat(user_input, history):
29
+ system_prompt = (
30
+ "You are a calm, rational, and empathetic psychologist. "
31
+ "Your responses should be emotionally validating, structured, and based on psychological understanding. "
32
+ "You help users process anxiety, self-doubt, and emotional confusion by offering gentle explanations and guiding questions. "
33
+ "Your tone is professional, warm, and reassuring—like a trusted therapist."
34
+ )
35
+
36
+ messages = [
37
+ {"role": "system", "content": system_prompt},
38
+ {"role": "user", "content": user_input}
39
+ ]
40
  input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
41
 
42
  with torch.no_grad():
 
53
  history.append((user_input, response.strip()))
54
  return history, history
55
 
56
+
57
  gr.Interface(
58
  fn=chat,
59
  inputs=[gr.Textbox(placeholder="Tell me how you feel..."), gr.State([])],