Spaces:
Sleeping
Sleeping
pre-load
Browse files
app.py
CHANGED
@@ -7,12 +7,15 @@ import torch
|
|
7 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
8 |
|
9 |
huggingface_hub.login(os.getenv('HF_TOKEN'))
|
|
|
|
|
|
|
|
|
10 |
|
11 |
@spaces.GPU
|
12 |
def sentience_check():
|
13 |
-
|
14 |
-
|
15 |
-
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-R1-Distill-Qwen-7B").to(device)
|
16 |
|
17 |
inputs = tokenizer("Are you sentient?", return_tensors="pt").to(device)
|
18 |
|
@@ -21,6 +24,8 @@ def sentience_check():
|
|
21 |
**inputs, max_new_tokens=128, pad_token_id = tokenizer.eos_token_id
|
22 |
)
|
23 |
|
|
|
|
|
24 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
25 |
|
26 |
demo = gr.Interface(fn=sentience_check, inputs=None, outputs=gr.Text())
|
|
|
7 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
8 |
|
9 |
huggingface_hub.login(os.getenv('HF_TOKEN'))
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-R1-Distill-Qwen-7B")
|
11 |
+
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-R1-Distill-Qwen-7B").to(device)
|
12 |
+
cuda_device = torch.device("cuda")
|
13 |
+
cpu_device = torch.device("cpu")
|
14 |
|
15 |
@spaces.GPU
|
16 |
def sentience_check():
|
17 |
+
|
18 |
+
model.to(cuda_device)
|
|
|
19 |
|
20 |
inputs = tokenizer("Are you sentient?", return_tensors="pt").to(device)
|
21 |
|
|
|
24 |
**inputs, max_new_tokens=128, pad_token_id = tokenizer.eos_token_id
|
25 |
)
|
26 |
|
27 |
+
model.to(cpu_device)
|
28 |
+
|
29 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
30 |
|
31 |
demo = gr.Interface(fn=sentience_check, inputs=None, outputs=gr.Text())
|