Update app.py
Browse files
app.py
CHANGED
|
@@ -1,67 +1,4 @@
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
"TurtleLiu/mistral7b_psychology_bot"
|
| 6 |
-
)
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def format_prompt(message, history):
|
| 10 |
-
prompt = "<s>"
|
| 11 |
-
for user_prompt, bot_response in history:
|
| 12 |
-
prompt += f"[INST] {user_prompt} [/INST]"
|
| 13 |
-
prompt += f" {bot_response}</s> "
|
| 14 |
-
prompt += f"[INST] {message} [/INST]"
|
| 15 |
-
return prompt
|
| 16 |
-
|
| 17 |
-
'''
|
| 18 |
-
def format_prompt(message, history):
|
| 19 |
-
prompt = "<s>"
|
| 20 |
-
for user_prompt, bot_response in history:
|
| 21 |
-
prompt += f"[INST] {user_prompt} [/INST]"
|
| 22 |
-
prompt += f" {bot_response}</s> "
|
| 23 |
-
prompt += f"[INST] As a psychology counselor assistant, provide an assessment and plan for the following counseling notes. Please present a summary, don't make it so long. Present in lines.: {message} [/INST]"
|
| 24 |
-
return prompt
|
| 25 |
-
'''
|
| 26 |
-
|
| 27 |
-
def generate(
|
| 28 |
-
prompt, history, temperature=0.9, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0,
|
| 29 |
-
):
|
| 30 |
-
temperature = float(temperature)
|
| 31 |
-
if temperature < 1e-2:
|
| 32 |
-
temperature = 1e-2
|
| 33 |
-
top_p = float(top_p)
|
| 34 |
-
|
| 35 |
-
generate_kwargs = dict(
|
| 36 |
-
temperature=temperature,
|
| 37 |
-
max_new_tokens=max_new_tokens,
|
| 38 |
-
top_p=top_p,
|
| 39 |
-
repetition_penalty=repetition_penalty,
|
| 40 |
-
do_sample=True,
|
| 41 |
-
seed=42,
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
formatted_prompt = format_prompt(f"{prompt}", history)
|
| 45 |
-
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 46 |
-
output = ""
|
| 47 |
-
|
| 48 |
-
for response in stream:
|
| 49 |
-
output += response.token.text
|
| 50 |
-
yield output
|
| 51 |
-
return output
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
examples=[
|
| 55 |
-
["Patient is feeling stressed due to work and has trouble sleeping.", None, None, None, None, None],
|
| 56 |
-
["Client is dealing with relationship issues and is seeking advice on communication strategies.", None, None, None, None, None],
|
| 57 |
-
["Individual has recently experienced a loss and is having difficulty coping with grief.", None, None, None, None, None],
|
| 58 |
-
]
|
| 59 |
-
|
| 60 |
-
gr.ChatInterface(
|
| 61 |
-
fn=generate,
|
| 62 |
-
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
| 63 |
-
title="Psychological Assistant: Expert in Assessment and Strategic Planning",
|
| 64 |
-
description="Enter counseling notes to generate an assessment and plan.",
|
| 65 |
-
examples=examples,
|
| 66 |
-
concurrency_limit=20,
|
| 67 |
-
).launch(show_api=False, debug=True)
|
|
|
|
| 1 |
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
gr.load("models/TurtleLiu/mistral7b_psychology_bot").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|