Spaces:
Sleeping
Sleeping
changed to use dclm model
Browse filesused apple's new dclm 7b model
app.py
CHANGED
@@ -1,11 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -25,23 +22,22 @@ def respond(
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
max_tokens
|
33 |
-
|
34 |
-
temperature
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
yield response
|
41 |
|
42 |
-
"""
|
43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
-
"""
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("apple/DCLM-Baseline-7B-8k")
|
5 |
+
model = AutoModelForCausalLM.from_pretrained("apple/DCLM-Baseline-7B-8k")
|
6 |
|
7 |
def respond(
|
8 |
message,
|
|
|
22 |
|
23 |
messages.append({"role": "user", "content": message})
|
24 |
|
25 |
+
prompt = "".join([f"{'[|Human|] ' if msg['role'] == 'user' else '[|AI|] '}{msg['content']}" for msg in messages])
|
26 |
|
27 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
28 |
+
gen_kwargs = {
|
29 |
+
"max_new_tokens": max_tokens,
|
30 |
+
"top_p": top_p,
|
31 |
+
"temperature": temperature,
|
32 |
+
"do_sample": True,
|
33 |
+
"repetition_penalty": 1.1
|
34 |
+
}
|
35 |
+
with torch.no_grad():
|
36 |
+
output = model.generate(inputs['input_ids'], **gen_kwargs)
|
37 |
+
response = tokenizer.decode(output[0].tolist(), skip_special_tokens=True)[len(prompt):]
|
38 |
|
39 |
+
yield response
|
|
|
40 |
|
|
|
|
|
|
|
41 |
demo = gr.ChatInterface(
|
42 |
respond,
|
43 |
additional_inputs=[
|