Download app.py from nadim71/LLM: direct link, hf CLI and curl.
- Browser
- Download file 561 Bytes
-
https://huggingface.co/spaces/nadim71/LLM/resolve/main/app.py
- Command line
-
hf download hf://spaces/nadim71/LLM/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nadim71/LLM/resolve/main/app.py
561 Bytes
| import gradio as gr | |
| import spaces | |
| import torch | |
| from transformers import AutoTokenizer | |
| # Check GPU | |
| zero = torch.tensor([0]).cuda() | |
| print(zero.device) # cuda:0 if GPU is available | |
| # Load tokenizer once | |
| tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased") | |
| def greet(sequence): | |
| tokens = tokenizer.tokenize(sequence) | |
| token_ids = tokenizer.convert_tokens_to_ids(tokens) | |
| return str(token_ids) | |
| demo = gr.Interface( | |
| fn=greet, | |
| inputs=gr.Textbox(label="Enter text"), | |
| outputs=gr.Textbox(label="Tokens"), | |
| ) | |
| demo.launch() |