Spaces:
Sleeping
Sleeping
space update
Browse files
app.py
CHANGED
|
@@ -28,6 +28,7 @@ def load_model():
|
|
| 28 |
context_length=context_length,
|
| 29 |
num_layers=num_layers
|
| 30 |
)
|
|
|
|
| 31 |
# Load the trained weights if available
|
| 32 |
model_path = "v1/u_model.pth"
|
| 33 |
|
|
@@ -37,18 +38,29 @@ def load_model():
|
|
| 37 |
try:
|
| 38 |
print("π₯ Downloading model weights from GitHub...")
|
| 39 |
import requests
|
| 40 |
-
url = "https://github.com/malibayram/llm-from-scratch/raw/main/u_model.pth"
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
response.raise_for_status() # Raise an exception for bad status codes
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# Create v1 directory if it doesn't exist
|
| 46 |
os.makedirs("v1", exist_ok=True)
|
| 47 |
-
|
| 48 |
# Save the model weights to the local file system
|
| 49 |
with open(model_path, "wb") as f:
|
| 50 |
f.write(response.content)
|
| 51 |
-
print("β
Model weights
|
| 52 |
except Exception as e:
|
| 53 |
print(f"β Failed to download model weights: {e}")
|
| 54 |
print("Using random initialization.")
|
|
@@ -153,14 +165,7 @@ demo = gr.ChatInterface(
|
|
| 153 |
),
|
| 154 |
],
|
| 155 |
title="π€ Usta Model Chat",
|
| 156 |
-
description="Chat with a custom transformer language model built from scratch! This model specializes in geographical knowledge including countries, capitals, and cities."
|
| 157 |
-
examples=[
|
| 158 |
-
"the capital of france",
|
| 159 |
-
"tell me about spain",
|
| 160 |
-
"what is the capital of united states",
|
| 161 |
-
"paris is in",
|
| 162 |
-
"germany and its capital"
|
| 163 |
-
]
|
| 164 |
)
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
|
|
|
| 28 |
context_length=context_length,
|
| 29 |
num_layers=num_layers
|
| 30 |
)
|
| 31 |
+
|
| 32 |
# Load the trained weights if available
|
| 33 |
model_path = "v1/u_model.pth"
|
| 34 |
|
|
|
|
| 38 |
try:
|
| 39 |
print("π₯ Downloading model weights from GitHub...")
|
| 40 |
import requests
|
| 41 |
+
url = "https://github.com/malibayram/llm-from-scratch/raw/main/v1/u_model.pth"
|
| 42 |
+
|
| 43 |
+
headers = {
|
| 44 |
+
'Accept': 'application/octet-stream',
|
| 45 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
response = requests.get(url, headers=headers)
|
| 49 |
response.raise_for_status() # Raise an exception for bad status codes
|
| 50 |
+
|
| 51 |
+
# Check if we got a proper binary file (PyTorch files start with specific bytes)
|
| 52 |
+
if response.content[:4] != b'PK\x03\x04' and b'<html' in response.content[:100].lower():
|
| 53 |
+
raise Exception("Downloaded HTML instead of binary file - check URL")
|
| 54 |
+
|
| 55 |
+
print(f"π¦ Downloaded {len(response.content)} bytes")
|
| 56 |
|
| 57 |
# Create v1 directory if it doesn't exist
|
| 58 |
os.makedirs("v1", exist_ok=True)
|
| 59 |
+
|
| 60 |
# Save the model weights to the local file system
|
| 61 |
with open(model_path, "wb") as f:
|
| 62 |
f.write(response.content)
|
| 63 |
+
print("β
Model weights saved successfully!")
|
| 64 |
except Exception as e:
|
| 65 |
print(f"β Failed to download model weights: {e}")
|
| 66 |
print("Using random initialization.")
|
|
|
|
| 165 |
),
|
| 166 |
],
|
| 167 |
title="π€ Usta Model Chat",
|
| 168 |
+
description="Chat with a custom transformer language model built from scratch! This model specializes in geographical knowledge including countries, capitals, and cities."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
)
|
| 170 |
|
| 171 |
if __name__ == "__main__":
|