|
from ctransformers import AutoModelForCausalLM, AutoTokenizer |
|
import gradio as gr |
|
|
|
sys_message = """ |
|
This model can generate untruths, lies or inappropriate things. Only for testing and validation. |
|
""" |
|
|
|
|
|
generation_config = { |
|
"max_new_tokens": 2048, |
|
"temperature": 0.50, |
|
"top_p": 0.95, |
|
"top_k": 30, |
|
"repetition_penalty": 1.1, |
|
"stop_token": '### Instruction:' |
|
} |
|
|
|
llm = AutoModelForCausalLM.from_pretrained("tevykuch/sl0th", hf=True) |
|
tokenizer = AutoTokenizer.from_pretrained(llm) |
|
|
|
def stream(prompt): |
|
|
|
inputs = tokenizer.encode(prompt, return_tensors="pt") |
|
|
|
output_ids = llm.generate(inputs, **generation_config) |
|
|
|
response = tokenizer.decode(output_ids[0], skip_special_tokens=True) |
|
return response |
|
|
|
|
|
|
|
chat_interface = gr.ChatInterface( |
|
fn=stream, |
|
stop_btn=None, |
|
examples=[ |
|
["ααΎαααα
ααααααΆααααΈααΆαα’αααΈαααα?"], |
|
["ααΎααΎαα’αΆα
ααΆαααααααααΆααααα»αααα·ααΆααΆααααΆαααΌα
ααααα
?"], |
|
["αααααΆααααΈαααααααΆαααα’αααααααΌαααααΎααΆααααααα
α
α·αααααααΆαα"], |
|
["αααααα’ααααααααΆααα½ααααα
ααα"], |
|
["αααααααΏαααααΈαα½ααααα»αααΆαααααΎαα·αααααααααααααα»ααααααΈααΈα’αααΈαα½α―ααααααααΌαααααΎααΆααααααα
α
α·αααα’αΆααΈαααααααΆαααα½αα"], |
|
["ααΆααααααααααααααααααααΆααααα α»αα’αααααΆαα·αα»ααααα·αααααααΆαααα"] |
|
], |
|
) |
|
|
|
with gr.Blocks() as demo: |
|
gr.HTML("<h1><center> sl0th inference tester only (not final) <h1><center>") |
|
gr.HTML( |
|
"<h4 style='text-align: center'>" |
|
"<a href='https://huggingface.co/tevykuch/sl0th' target='_blank'>Model: Sl0th Mistral 7b 0.2</a> | " |
|
"</h4>" |
|
) |
|
gr.HTML("<p><center>Finetune here <a href='https://huggingface.co/unsloth/mistral-7b-bnb-4bit' target='_blank'>Mistral 7b</a> thanks dataset maker (my coworker) <a href='https://huggingface.co/datasets/metythorn/khmerllm-dataset-alpaca-52k-v1'>Alpaca-data-pt-br</a>.<p><center>") |
|
chat_interface.render() |
|
gr.Markdown(sys_message) |
|
gr.DuplicateButton(value="Duplicate the Magic", elem_id="duplicate-button") |
|
|
|
if __name__ == "__main__": |
|
demo.queue(max_size=10).launch() |