yoooo?
Browse files- app.py +27 -9
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,12 +1,23 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
|
|
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
@@ -26,14 +37,21 @@ def respond(
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
for message in
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
token = message.choices[0].delta.content
|
38 |
|
39 |
response += token
|
|
|
1 |
+
#pip install transformers flash_attn
|
2 |
import gradio as gr
|
3 |
+
import spaces
|
4 |
+
import torch
|
5 |
|
6 |
"""
|
7 |
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
|
8 |
"""
|
9 |
+
|
10 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained("jpacifico/Chocolatine-14B-Instruct-DPO-v1.2")
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(
|
13 |
+
"jpacifico/Chocolatine-14B-Instruct-DPO-v1.2",
|
14 |
+
device_map="cuda",
|
15 |
+
torch_dtype="auto",
|
16 |
+
trust_remote_code=True,
|
17 |
+
)
|
18 |
|
19 |
|
20 |
+
@spaces.GPU
|
21 |
def respond(
|
22 |
message,
|
23 |
history: list[tuple[str, str]],
|
|
|
37 |
messages.append({"role": "user", "content": message})
|
38 |
|
39 |
response = ""
|
40 |
+
|
41 |
+
prompt = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
|
42 |
+
# Generate text
|
43 |
+
# messages = model.generate(prompt, max_new_tokens=512)
|
44 |
+
|
45 |
+
messages = model.generate(
|
46 |
+
prompt,
|
47 |
+
do_sample=True,
|
48 |
+
temperature=0.7,
|
49 |
+
top_p=0.9,
|
50 |
+
num_return_sequences=1,
|
51 |
+
max_length=200
|
52 |
+
)
|
53 |
|
54 |
+
for message in messages:
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
token = message.choices[0].delta.content
|
56 |
|
57 |
response += token
|
requirements.txt
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
huggingface_hub==0.22.2
|
|
|
|
|
|
1 |
+
huggingface_hub==0.22.2
|
2 |
+
transformers[torch]
|
3 |
+
flash_attn
|