Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,13 @@ import gradio as gr
|
|
2 |
from transformers import AutoTokenizer
|
3 |
from huggingface_hub import HfApi
|
4 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
|
|
|
|
|
|
5 |
|
6 |
def count_tokens(model_id, text):
|
7 |
try:
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
9 |
tokens = tokenizer.encode(text)
|
10 |
|
11 |
token_count = len(tokens)
|
|
|
2 |
from transformers import AutoTokenizer
|
3 |
from huggingface_hub import HfApi
|
4 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
5 |
+
import os
|
6 |
+
|
7 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
8 |
|
9 |
def count_tokens(model_id, text):
|
10 |
try:
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, token=HF_TOKEN)
|
12 |
tokens = tokenizer.encode(text)
|
13 |
|
14 |
token_count = len(tokens)
|