Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,33 @@
|
|
1 |
-
from
|
2 |
import gradio as gr
|
3 |
|
4 |
sys_message = """
|
5 |
This model can generate untruths, lies or inappropriate things. Only for testing and validation.
|
6 |
"""
|
7 |
|
8 |
-
# Configuration settings for model generation (example)
|
9 |
-
generation_config = {
|
10 |
-
"max_new_tokens": 2048,
|
11 |
-
"temperature": 0.50,
|
12 |
-
"top_p": 0.95,
|
13 |
-
"top_k": 30,
|
14 |
-
"repetition_penalty": 1.1,
|
15 |
-
"stop_token": '### Instruction:'
|
16 |
-
}
|
17 |
-
|
18 |
-
llm = AutoModel.from_pretrained("tevykuch/sftsl0th")
|
19 |
-
# llm = AutoModelForCausalLM.from_pretrained("tevykuch/sl0th", hf=True)
|
20 |
-
tokenizer = AutoTokenizer.from_pretrained(llm)
|
21 |
-
|
22 |
-
def stream(prompt):
|
23 |
-
# Tokenize the prompt
|
24 |
-
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
25 |
-
# Generate a response
|
26 |
-
output_ids = llm.generate(inputs, **generation_config)
|
27 |
-
# Decode the generated ids to a string
|
28 |
-
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
29 |
-
return response
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
chat_interface = gr.ChatInterface(
|
|
|
1 |
+
from ctransformers import AutoModelForCausalLM
|
2 |
import gradio as gr
|
3 |
|
4 |
sys_message = """
|
5 |
This model can generate untruths, lies or inappropriate things. Only for testing and validation.
|
6 |
"""
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
llm = AutoModelForCausalLM.from_pretrained("tevykuch/sftsl0th",
|
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 |
chat_interface = gr.ChatInterface(
|