tevy kuch
commited on
Commit
Β·
6447476
1
Parent(s):
b902943
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from ctransformers import AutoModelForCausalLM
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
sys_message = """
|
6 |
+
This model can generate untruths, lies or inappropriate things. Only for testing and validation.
|
7 |
+
"""
|
8 |
+
|
9 |
+
llm = AutoModelForCausalLM.from_pretrained("tevykuch/sl0th", model_file="sl0th-unsloth.F16.gguf",
|
10 |
+
model_type='mistral',
|
11 |
+
max_new_tokens = 2048,
|
12 |
+
threads = 2,
|
13 |
+
temperature = 0.50,
|
14 |
+
top_p = 0.95,
|
15 |
+
top_k = 30,
|
16 |
+
repetition_penalty = 1.1,
|
17 |
+
stop=['### Instruction:']
|
18 |
+
)
|
19 |
+
|
20 |
+
def stream(prompt, UL):
|
21 |
+
system_prompt = 'You are a helpful chatbot. You only answer in Khmer. User is based in Cambodia. Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.'
|
22 |
+
E_INST = " "
|
23 |
+
system, user, assistant = "###Instruction", "###Input", "###Response"
|
24 |
+
prompt = f"{system}\n{system_prompt}{E_INST}\n{user}\n{prompt.strip()}{E_INST}\n{assistant}\n"
|
25 |
+
|
26 |
+
output = ""
|
27 |
+
for response in llm(prompt, stream=True):
|
28 |
+
output += response
|
29 |
+
yield output
|
30 |
+
return output
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
chat_interface = gr.ChatInterface(
|
35 |
+
fn=stream,
|
36 |
+
stop_btn=None,
|
37 |
+
examples=[
|
38 |
+
["ααΎαααα
ααααααΆααααΈααΆαα’αααΈαααα?"],
|
39 |
+
["ααΎααΎαα’αΆα
ααΆαααααααααΆααααα»αααα·ααΆααΆααααΆαααΌα
ααααα
?"],
|
40 |
+
["αααααΆααααΈαααααααΆαααα’αααααααΌαααααΎααΆααααααα
α
α·αααααααΆαα"],
|
41 |
+
["αααααα’ααααααααΆααα½ααααα
ααα"],
|
42 |
+
["αααααααΏαααααΈαα½ααααα»αααΆαααααΎαα·αααααααααααααα»ααααααΈααΈα’αααΈαα½α―ααααααααΌαααααΎααΆααααααα
α
α·αααα’αΆααΈαααααααΆαααα½αα"],
|
43 |
+
["ααΆααααααααααααααααααααΆααααα α»αα’αααααΆαα·αα»ααααα·αααααααΆαααα"]
|
44 |
+
],
|
45 |
+
)
|
46 |
+
|
47 |
+
with gr.Blocks() as demo:
|
48 |
+
gr.HTML("<h1><center> sl0th <h1><center>")
|
49 |
+
gr.HTML(
|
50 |
+
"<h4 style='text-align: center'>"
|
51 |
+
"<a href='https://huggingface.co/nicolasdec/CabraMistral7b-0.2' target='_blank'>Modelo: Cabra Mistral 7b 0.2</a> | "
|
52 |
+
"π <a href='https://huggingface.co/collections/nicolasdec/cabra-65d12286c4d2b2e4029c0c63' target='_blank'>Outros modelos Cabra</a>"
|
53 |
+
"</h4>"
|
54 |
+
)
|
55 |
+
gr.HTML("<p><center>Finetune do <a href='https://huggingface.co/unsloth/mistral-7b-bnb-4bit' target='_blank'>Mistral 7b</a> com o dataset <a href='https://huggingface.co/datasets/dominguesm/alpaca-data-pt-br' target='_blank'>Alpaca-data-pt-br</a>.<p><center>")
|
56 |
+
chat_interface.render()
|
57 |
+
gr.Markdown(sys_message)
|
58 |
+
gr.DuplicateButton(value="Duplicar espaço para GPU", elem_id="duplicate-button")
|
59 |
+
|
60 |
+
if __name__ == "__main__":
|
61 |
+
demo.queue(max_size=10).launch()
|