Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,5 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
import torch
|
| 4 |
-
import gradio as gr
|
| 5 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 6 |
-
|
| 7 |
-
# Handle Hugging Face Spaces GPU
|
| 8 |
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
| 9 |
import spaces
|
| 10 |
else:
|
|
@@ -18,6 +13,12 @@ else:
|
|
| 18 |
@spaces.GPU
|
| 19 |
def fake_gpu():
|
| 20 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Available models
|
| 23 |
AVAILABLE_MODELS = {
|
|
@@ -45,6 +46,7 @@ def load_model(model_name):
|
|
| 45 |
# Load the default model at startup
|
| 46 |
load_model("distilgpt2")
|
| 47 |
|
|
|
|
| 48 |
def get_next_token_predictions(text, model_name, top_k=10):
|
| 49 |
"""Generate the next token predictions with their probabilities."""
|
| 50 |
global current_model, current_tokenizer
|
|
|
|
| 1 |
import os
|
| 2 |
+
# Handle Spaces GPU
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
| 4 |
import spaces
|
| 5 |
else:
|
|
|
|
| 13 |
@spaces.GPU
|
| 14 |
def fake_gpu():
|
| 15 |
pass
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
import torch
|
| 19 |
+
import gradio as gr
|
| 20 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 21 |
+
import spaces
|
| 22 |
|
| 23 |
# Available models
|
| 24 |
AVAILABLE_MODELS = {
|
|
|
|
| 46 |
# Load the default model at startup
|
| 47 |
load_model("distilgpt2")
|
| 48 |
|
| 49 |
+
@spaces.GPU()
|
| 50 |
def get_next_token_predictions(text, model_name, top_k=10):
|
| 51 |
"""Generate the next token predictions with their probabilities."""
|
| 52 |
global current_model, current_tokenizer
|