CoolFace
Apppublic

TurtleLiu/Code_Assist_Test

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py61 linesDownload Raw Back to root
1from huggingface_hub import InferenceClient2import gradio as gr3 4client = InferenceClient(5    "facebook/incoder-1B"6)7 8 9 10 11def format_prompt(message, history):12  prompt = "<s>"13  for user_prompt, bot_response in history:14    prompt += f"[INST] {user_prompt} [/INST]"15    prompt += f" {bot_response}</s> "16  prompt += f"[INST] {message} [/INST]"17  return prompt18 19 20    21def generate(22    prompt, history, temperature=0.9, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0,23):24    temperature = float(temperature)25    if temperature < 1e-2:26        temperature = 1e-227    top_p = float(top_p)28 29    generate_kwargs = dict(30        temperature=temperature,31        max_new_tokens=max_new_tokens,32        top_p=top_p,33        repetition_penalty=repetition_penalty,34        do_sample=True,35        seed=42,36    )37 38    formatted_prompt = format_prompt(f"{prompt}", history)39    stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)40    output = ""41 42    for response in stream:43        output += response.token.text44        yield output45    return output46 47 48examples=[49    ["Patient is feeling stressed due to work and has trouble sleeping.", None, None, None, None, None],50    ["Client is dealing with relationship issues and is seeking advice on communication strategies.", None, None, None, None, None],51    ["Individual has recently experienced a loss and is having difficulty coping with grief.", None, None, None, None, None],52]53 54gr.ChatInterface(55    fn=generate,56    chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),57    title="Psychological Assistant: Expert in Assessment and Strategic Planning",58    description="Enter counseling notes to generate an assessment and plan.",59    examples=examples,60    concurrency_limit=20,61).launch(show_api=False, debug=True)