Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,24 @@ def format_prompt(message, history):
|
|
41 |
prompt += f"[INST] {message} [/INST]"
|
42 |
return prompt
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
temperature = float(temperature)
|
46 |
if temperature < 1e-2:
|
47 |
temperature = 1e-2
|
@@ -58,6 +75,22 @@ def generate_response(prompt, history, temperature=0.9, max_new_tokens=1024, top
|
|
58 |
runtimeFlag = "cuda:0"
|
59 |
formatted_prompt = format_prompt(f"{prompt}", history)
|
60 |
inputs = tokenizer([formatted_prompt], return_tensors="pt").to(runtimeFlag)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
# UI design
|
63 |
examples=[
|
@@ -67,7 +100,7 @@ examples=[
|
|
67 |
]
|
68 |
|
69 |
gr.ChatInterface(
|
70 |
-
fn=
|
71 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
72 |
title="Psychological Assistant: Expert in Assessment and Strategic Planning",
|
73 |
description="Enter counseling notes to generate an assessment and plan.",
|
|
|
41 |
prompt += f"[INST] {message} [/INST]"
|
42 |
return prompt
|
43 |
|
44 |
+
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200, do_sample=True,
|
45 |
+
max_new_tokens=1024,
|
46 |
+
temperature=0.9,
|
47 |
+
top_k=50,
|
48 |
+
top_p=0.95,
|
49 |
+
num_return_sequences=1)
|
50 |
+
|
51 |
+
def generate_response(message, history):
|
52 |
+
prompt = "<s>"
|
53 |
+
for user_prompt, bot_response in history:
|
54 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
55 |
+
prompt += f" {bot_response}</s> "
|
56 |
+
prompt += f"[INST] {message} [/INST]"
|
57 |
+
result = pipe(f"{prompt}")[0]['generated_text']
|
58 |
+
return result
|
59 |
+
|
60 |
+
'''
|
61 |
+
def generate_response(prompt, history, temperature=0.9, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0, **kwargs,):
|
62 |
temperature = float(temperature)
|
63 |
if temperature < 1e-2:
|
64 |
temperature = 1e-2
|
|
|
75 |
runtimeFlag = "cuda:0"
|
76 |
formatted_prompt = format_prompt(f"{prompt}", history)
|
77 |
inputs = tokenizer([formatted_prompt], return_tensors="pt").to(runtimeFlag)
|
78 |
+
generation_config = GenerationConfig(
|
79 |
+
temperature=temperature,
|
80 |
+
top_p=top_p,
|
81 |
+
max_new_tokens=max_new_tokens,
|
82 |
+
repetition_penalty=repetition_penalty,
|
83 |
+
do_sample=True,
|
84 |
+
**kwargs,
|
85 |
+
)
|
86 |
+
generation_output = model.generate(
|
87 |
+
**inputs,
|
88 |
+
generation_config=generation_config,
|
89 |
+
return_dict_in_generate=True,
|
90 |
+
output_scores=True,
|
91 |
+
max_new_tokens=max_new_tokens,
|
92 |
+
)
|
93 |
+
'''
|
94 |
|
95 |
# UI design
|
96 |
examples=[
|
|
|
100 |
]
|
101 |
|
102 |
gr.ChatInterface(
|
103 |
+
fn=generate_response,
|
104 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
105 |
title="Psychological Assistant: Expert in Assessment and Strategic Planning",
|
106 |
description="Enter counseling notes to generate an assessment and plan.",
|