Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
import sys
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
sys.path.insert(0, os.path.dirname(__file__))
|
| 7 |
|
|
@@ -15,9 +16,14 @@ print(f"Loading on {device}")
|
|
| 15 |
config = NexusConfig()
|
| 16 |
model = Nexus(config)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
checkpoint = torch.load(weights_path, map_location=device, weights_only=False)
|
| 23 |
model.load_state_dict(checkpoint["model_state_dict"])
|
|
@@ -25,7 +31,11 @@ model = model.to(device)
|
|
| 25 |
model.eval()
|
| 26 |
print("Model loaded")
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
tokenizer = Tokenizer.from_file(tokenizer_path)
|
| 30 |
|
| 31 |
bos_id = tokenizer.token_to_id("<bos>") or 1
|
|
|
|
| 2 |
import torch
|
| 3 |
import sys
|
| 4 |
import os
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
sys.path.insert(0, os.path.dirname(__file__))
|
| 8 |
|
|
|
|
| 16 |
config = NexusConfig()
|
| 17 |
model = Nexus(config)
|
| 18 |
|
| 19 |
+
REPO = "JustScriptzz/nexus-smAll-v1"
|
| 20 |
+
|
| 21 |
+
weights_local = os.path.join(os.path.dirname(__file__), "weights", "nexus_instruct.pt")
|
| 22 |
+
if os.path.exists(weights_local):
|
| 23 |
+
weights_path = weights_local
|
| 24 |
+
else:
|
| 25 |
+
print("Downloading weights from HuggingFace...")
|
| 26 |
+
weights_path = hf_hub_download(repo_id=REPO, filename="weights/nexus_instruct.pt")
|
| 27 |
|
| 28 |
checkpoint = torch.load(weights_path, map_location=device, weights_only=False)
|
| 29 |
model.load_state_dict(checkpoint["model_state_dict"])
|
|
|
|
| 31 |
model.eval()
|
| 32 |
print("Model loaded")
|
| 33 |
|
| 34 |
+
tokenizer_local = os.path.join(os.path.dirname(__file__), "data", "tokenizer.json")
|
| 35 |
+
if os.path.exists(tokenizer_local):
|
| 36 |
+
tokenizer_path = tokenizer_local
|
| 37 |
+
else:
|
| 38 |
+
tokenizer_path = hf_hub_download(repo_id=REPO, filename="data/tokenizer.json")
|
| 39 |
tokenizer = Tokenizer.from_file(tokenizer_path)
|
| 40 |
|
| 41 |
bos_id = tokenizer.token_to_id("<bos>") or 1
|