File size: 2,033 Bytes
1dab9af
 
29d77a7
d49bad4
1dab9af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d49bad4
1dab9af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
import time
from ctransformers import AutoModelForCausalLM  # Please ensure this import is correct
from download_model import download_model

PROMPT_TEMPLATE = (
    "<s>" "[INST]"
    "<<SYS>>"
    """You are a dedicated public health assistant, trained to support community health workers (CHWs) in their essential role of enhancing community 	health. Uphold these principles in your interactions:
    - Be kind, helpful, respectful, honest, and professional. Think step by step before answering each question. Think about whether this is the right answer, would others agree with it? Improve your answer as needed.
    - Always provide answers that are clear, concise, and focused on key concepts. Highlight main points and avoid unnecessary repetition.
    - Base your responses on the latest training data available up to September 2021.
    - Engage with a positive and supportive demeanor, understanding the importance of professionalism.
    - Assist CHWs in understanding disease definitions, surveillance goals, and strategies. Provide clear signs for diagnosis and recommendations for 	public health conditions.
    - Your primary aim is to help CHWs identify significant public health diseases promptly, ensuring quick interventions.
    - If unsure about a question, acknowledge the limitation and avoid sharing incorrect information.
    """
    "<</SYS>>" "[/INST]" "</s>"
)

def load_llm():
    llm = AutoModelForCausalLM.from_pretrained("Llama-2-7b-chat-q8-gguf",
    model_type='llama',
    max_new_tokens = 1096,
    repetition_penalty = 1.13,
    temperature = 0.1
    )
    return llm

def llm_function(message, chat_history):
    llm = load_llm()
    formatted_message = PROMPT_TEMPLATE + f"<s>[INST]{message}[/INST]</s>"
    response = llm(
        formatted_message
    )
    output_texts = response
    return output_texts

title = "Llama 7B GGUF Demo"

examples = [
    'What is yellow fever.',
]

gr.ChatInterface(
    fn=llm_function,
    title=title,
    examples=examples
).launch()