Spaces:
Sleeping
Sleeping
space update
Browse files- app.py +8 -10
- requirements.txt +1 -0
app.py
CHANGED
@@ -11,6 +11,7 @@ from v1.usta_tokenizer import UstaTokenizer
|
|
11 |
def load_model():
|
12 |
try:
|
13 |
u_tokenizer = UstaTokenizer("v1/tokenizer.json")
|
|
|
14 |
|
15 |
# Model parameters - adjust these to match your trained model
|
16 |
context_length = 32
|
@@ -27,11 +28,13 @@ def load_model():
|
|
27 |
context_length=context_length,
|
28 |
num_layers=num_layers
|
29 |
)
|
|
|
30 |
|
31 |
# Load the trained weights if available
|
32 |
model_path = "v1/u_model.pth"
|
33 |
|
34 |
if not os.path.exists(model_path):
|
|
|
35 |
# Download the model file from GitHub
|
36 |
try:
|
37 |
print("π₯ Downloading model weights from GitHub...")
|
@@ -39,10 +42,12 @@ def load_model():
|
|
39 |
url = "https://github.com/malibayram/llm-from-scratch/raw/main/u_model.pth"
|
40 |
response = requests.get(url)
|
41 |
response.raise_for_status() # Raise an exception for bad status codes
|
|
|
42 |
|
43 |
# Create v1 directory if it doesn't exist
|
44 |
os.makedirs("v1", exist_ok=True)
|
45 |
-
|
|
|
46 |
with open(model_path, "wb") as f:
|
47 |
f.write(response.content)
|
48 |
print("β
Model weights downloaded successfully!")
|
@@ -52,7 +57,7 @@ def load_model():
|
|
52 |
|
53 |
if os.path.exists(model_path):
|
54 |
try:
|
55 |
-
u_model.load_state_dict(torch.load(model_path, map_location="cpu"))
|
56 |
u_model.eval()
|
57 |
print("β
Model weights loaded successfully!")
|
58 |
except Exception as e:
|
@@ -150,14 +155,7 @@ demo = gr.ChatInterface(
|
|
150 |
),
|
151 |
],
|
152 |
title="π€ Usta Model Chat",
|
153 |
-
description="Chat with a custom transformer language model built from scratch! This model specializes in geographical knowledge including countries, capitals, and cities."
|
154 |
-
examples=[
|
155 |
-
"the capital of france",
|
156 |
-
"tell me about spain",
|
157 |
-
"what is the capital of united states",
|
158 |
-
"paris is in",
|
159 |
-
"germany and its capital"
|
160 |
-
]
|
161 |
)
|
162 |
|
163 |
if __name__ == "__main__":
|
|
|
11 |
def load_model():
|
12 |
try:
|
13 |
u_tokenizer = UstaTokenizer("v1/tokenizer.json")
|
14 |
+
print("β
Tokenizer loaded successfully! vocab size:", len(u_tokenizer.vocab))
|
15 |
|
16 |
# Model parameters - adjust these to match your trained model
|
17 |
context_length = 32
|
|
|
28 |
context_length=context_length,
|
29 |
num_layers=num_layers
|
30 |
)
|
31 |
+
print("β
Model loaded successfully! vocab size:", len(u_model.vocab))
|
32 |
|
33 |
# Load the trained weights if available
|
34 |
model_path = "v1/u_model.pth"
|
35 |
|
36 |
if not os.path.exists(model_path):
|
37 |
+
print("β Model file not found at", model_path)
|
38 |
# Download the model file from GitHub
|
39 |
try:
|
40 |
print("π₯ Downloading model weights from GitHub...")
|
|
|
42 |
url = "https://github.com/malibayram/llm-from-scratch/raw/main/u_model.pth"
|
43 |
response = requests.get(url)
|
44 |
response.raise_for_status() # Raise an exception for bad status codes
|
45 |
+
print("β
Model weights downloaded successfully!")
|
46 |
|
47 |
# Create v1 directory if it doesn't exist
|
48 |
os.makedirs("v1", exist_ok=True)
|
49 |
+
|
50 |
+
# Save the model weights to the local file system
|
51 |
with open(model_path, "wb") as f:
|
52 |
f.write(response.content)
|
53 |
print("β
Model weights downloaded successfully!")
|
|
|
57 |
|
58 |
if os.path.exists(model_path):
|
59 |
try:
|
60 |
+
u_model.load_state_dict(torch.load(model_path, map_location="cpu", weights_only=False))
|
61 |
u_model.eval()
|
62 |
print("β
Model weights loaded successfully!")
|
63 |
except Exception as e:
|
|
|
155 |
),
|
156 |
],
|
157 |
title="π€ Usta Model Chat",
|
158 |
+
description="Chat with a custom transformer language model built from scratch! This model specializes in geographical knowledge including countries, capitals, and cities."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
)
|
160 |
|
161 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
|
|
1 |
torch>=2.7.1
|
2 |
requests>=2.32.4
|
|
|
1 |
+
gradio>=5.33.1
|
2 |
torch>=2.7.1
|
3 |
requests>=2.32.4
|