|
import gradio as gr |
|
from ctransformers import AutoTokenizer, AutoModelForCausalLM |
|
|
|
|
|
model_id = "TheBloke/Mistral-7B-Instruct-v0.1-GGUF" |
|
model_file = "mistral-7b-instruct-v0.1.Q4_K_M.gguf" |
|
model_type = "mistral" |
|
|
|
|
|
quant_model = AutoModelForCausalLM.from_pretrained(model_id, model_file = model_file , model_type= model_type) |
|
|
|
|
|
def lechat_respond( |
|
message, |
|
history: list[tuple[str, str]], |
|
max_tokens, |
|
temperature, |
|
top_p, |
|
top_k |
|
): |
|
|
|
text = f"""<s>[INST] {message} [/INST]""" |
|
|
|
response = "" |
|
|
|
for next_token in quant_model(text, |
|
max_new_tokens = int(max_tokens), |
|
temperature = temperature, |
|
top_p = top_p, |
|
top_k = top_k, |
|
stream = True): |
|
response += next_token |
|
yield response |
|
|
|
|
|
|
|
mistral_chat = gr.ChatInterface( |
|
fn = lechat_respond, |
|
type = 'messages', |
|
|
|
|
|
additional_inputs=[ |
|
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), |
|
gr.Slider(minimum=0.1, maximum=4.0, value=0.8, step=0.1, label="Temperature"), |
|
gr.Slider(minimum=0.1,maximum=1.0,value=0.95,step=0.05,label="Top-p (nucleus sampling)"), |
|
gr.Slider(minimum = 40, maximum = 10000, value = 40, step = 10, label = "Top-k"), |
|
], |
|
|
|
|
|
|
|
) |
|
|
|
if __name__ == "__main__": |
|
mistral_chat.launch() |
|
|