Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,20 +2,42 @@ import gradio as gr
|
|
2 |
import spaces
|
3 |
import time
|
4 |
import os
|
|
|
|
|
|
|
5 |
key = (os.getenv('API_KEY'))
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
# Utiliser le jeton d'accès API pour charger le modèle
|
9 |
-
from transformers import pipeline
|
10 |
|
11 |
messages = [
|
|
|
12 |
{"role": "user", "content": "Who are you?"},
|
13 |
]
|
14 |
-
|
15 |
-
|
16 |
-
tokenizer
|
|
|
|
|
17 |
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
@spaces.GPU(duration=240)
|
21 |
|
|
|
2 |
import spaces
|
3 |
import time
|
4 |
import os
|
5 |
+
from transformers import pipeline
|
6 |
+
import torch
|
7 |
+
|
8 |
key = (os.getenv('API_KEY'))
|
9 |
+
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
pipeline = transformers.pipeline(
|
14 |
+
"text-generation",
|
15 |
+
model=model_id,
|
16 |
+
model_kwargs={"torch_dtype": torch.bfloat16},
|
17 |
+
device_map="auto",
|
18 |
+
token = key
|
19 |
+
)
|
20 |
|
|
|
|
|
21 |
|
22 |
messages = [
|
23 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
24 |
{"role": "user", "content": "Who are you?"},
|
25 |
]
|
26 |
+
|
27 |
+
terminators = [
|
28 |
+
pipeline.tokenizer.eos_token_id,
|
29 |
+
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
30 |
+
]
|
31 |
|
32 |
|
33 |
+
outputs = pipeline(
|
34 |
+
messages,
|
35 |
+
max_new_tokens=256,
|
36 |
+
eos_token_id=terminators,
|
37 |
+
do_sample=True,
|
38 |
+
temperature=0.6,
|
39 |
+
top_p=0.9,
|
40 |
+
)
|
41 |
|
42 |
@spaces.GPU(duration=240)
|
43 |
|