Spaces:
Sleeping
Sleeping
add demo
Browse files
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
-
title: Salamandra On
|
3 |
-
emoji:
|
4 |
colorFrom: indigo
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
+
title: Salamandra On-Device
|
3 |
+
emoji: 📲🦎
|
4 |
colorFrom: indigo
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline, set_seed
|
|
|
|
|
3 |
import torch
|
4 |
|
5 |
description = "The models are intended for both research and commercial use in any of the languages included in the training data. The base models are intended either for language generation or to be further fine-tuned for specific use-cases. The instruction-tuned variants can be used as general-purpose assistants, as long as the user is fully aware of the model’s limitations."
|
@@ -11,7 +13,13 @@ joinus = """
|
|
11 |
|
12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
13 |
model_id = "BSC-LT/salamandra-2b"
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def generate_text(prompt, temperature, top_p, max_new_tokens, repetition_penalty):
|
17 |
# set_seed(42)
|
@@ -20,7 +28,8 @@ def generate_text(prompt, temperature, top_p, max_new_tokens, repetition_penalty
|
|
20 |
"top_p": top_p,
|
21 |
"max_new_tokens": max_new_tokens,
|
22 |
"repetition_penalty": repetition_penalty,
|
23 |
-
"do_sample": True
|
|
|
24 |
}
|
25 |
output = generator(prompt, **generation_args)
|
26 |
return output[0]["generated_text"]
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline, set_seed
|
3 |
+
from transformers import pipeline, set_seed, AutoTokenizer, AutoModelForCausalLM
|
4 |
+
|
5 |
import torch
|
6 |
|
7 |
description = "The models are intended for both research and commercial use in any of the languages included in the training data. The base models are intended either for language generation or to be further fine-tuned for specific use-cases. The instruction-tuned variants can be used as general-purpose assistants, as long as the user is fully aware of the model’s limitations."
|
|
|
13 |
|
14 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
15 |
model_id = "BSC-LT/salamandra-2b"
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
17 |
+
model = AutoModelForCausalLM.from_pretrained(model_id).to(device)
|
18 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device_map="auto")
|
19 |
+
|
20 |
+
# Set pad_token_id to eos_token_id for open-end generation
|
21 |
+
if tokenizer.pad_token_id is None:
|
22 |
+
tokenizer.pad_token_id = tokenizer.eos_token_id
|
23 |
|
24 |
def generate_text(prompt, temperature, top_p, max_new_tokens, repetition_penalty):
|
25 |
# set_seed(42)
|
|
|
28 |
"top_p": top_p,
|
29 |
"max_new_tokens": max_new_tokens,
|
30 |
"repetition_penalty": repetition_penalty,
|
31 |
+
"do_sample": True,
|
32 |
+
"pad_token_id": tokenizer.eos_token_id
|
33 |
}
|
34 |
output = generator(prompt, **generation_args)
|
35 |
return output[0]["generated_text"]
|