Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,46 +10,13 @@ api_token = os.environ.get("APIKEY")
|
|
10 |
|
11 |
|
12 |
|
13 |
-
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
|
14 |
@spaces.GPU(duration=240)
|
|
|
|
|
15 |
|
16 |
-
|
|
|
17 |
|
18 |
-
pipeline = transformers.pipeline(
|
19 |
-
"text-generation",
|
20 |
-
model=model_id,
|
21 |
-
token = api_token,
|
22 |
-
model_kwargs={"torch_dtype": torch.bfloat16},
|
23 |
-
device_map="auto",
|
24 |
-
)
|
25 |
-
|
26 |
-
# Créer un pipeline pour la génération de texte
|
27 |
-
pipeline = transformers.pipeline(
|
28 |
-
"text-generation",
|
29 |
-
model=model,
|
30 |
-
tokenizer=model.config.tokenizer,
|
31 |
-
device_map="auto",
|
32 |
-
)
|
33 |
-
|
34 |
-
messages = [
|
35 |
-
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
36 |
-
{"role": "user", "content": "Who are you?"},
|
37 |
-
]
|
38 |
-
|
39 |
-
terminators = [
|
40 |
-
pipeline.tokenizer.eos_token_id,
|
41 |
-
pipeline.tokenizer.convert_tokens_to_ids("")
|
42 |
-
]
|
43 |
-
|
44 |
-
# Utiliser le pipeline pour générer du texte
|
45 |
-
outputs = pipeline(
|
46 |
-
messages,
|
47 |
-
max_new_tokens=256,
|
48 |
-
eos_token_id=terminators,
|
49 |
-
do_sample=True,
|
50 |
-
temperature=0.6,
|
51 |
-
top_p=0.9,
|
52 |
-
)
|
53 |
|
54 |
|
55 |
# Fonction de génération de texte
|
|
|
10 |
|
11 |
|
12 |
|
|
|
13 |
@spaces.GPU(duration=240)
|
14 |
+
# Load model directly
|
15 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
16 |
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")
|
18 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct",token=api_token)
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
# Fonction de génération de texte
|