File size: 1,508 Bytes
bb517ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
import os
from easyllm.clients import huggingface
from easyllm.prompt_utils import build_llama2_prompt

huggingface.prompt_builder = build_llama2_prompt

system_message = "\nYou are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe.  Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."
title = "Llama2 70B Chatbot with EasyLLM"
description = """This Space demonstrates model [Llama-2-70b-chat-hf](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) by Meta with EasyLLM (https://philschmid.github.io/easyllm)""" 
css = """.toast-wrap { display: none !important } """

def predict(message, chatbot):
 
    response = huggingface.ChatCompletion.create(
        model="meta-llama/Llama-2-70b-chat-hf",
        messages=[
            {"role": "system", "content": system_message},
            {"role": "user", "content": message},
        ],
          temperature=0.9,
          top_p=0.6,
          max_tokens=256,
    )
    return response['choices'][0]['message']['content']

gr.ChatInterface(predict, title=title, description=description, css=css).queue(concurrency_count=75).launch()