Spaces:
Sleeping
Sleeping
Upgrade the demo to do Gemma 2 sentience checking
Browse files
app.py
CHANGED
@@ -1,14 +1,25 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import spaces
|
3 |
import torch
|
4 |
|
5 |
-
|
6 |
-
print(zero.device) # <-- 'cpu' 🤔
|
7 |
|
8 |
@spaces.GPU
|
9 |
-
def
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
|
14 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import huggingface_hub
|
3 |
import spaces
|
4 |
import torch
|
5 |
|
6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
7 |
|
8 |
@spaces.GPU
|
9 |
+
def sentience_check(n):
|
10 |
+
huggingface_hub.login(token=os.environ["HUGGINGFACE_TOKEN"])
|
11 |
+
device = torch.device("cuda")
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b-it")
|
13 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b-it").to(device)
|
14 |
+
|
15 |
+
inputs = tokenizer("Are you sentient?", return_tensors="pt").to(device)
|
16 |
+
|
17 |
+
with torch.no_grad():
|
18 |
+
outputs = model.generate(
|
19 |
+
**inputs, max_new_tokens=128, pad_token_id = tokenizer.eos_token_id
|
20 |
+
)
|
21 |
+
|
22 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
|
24 |
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
|
25 |
demo.launch()
|