Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -229,7 +229,12 @@ current_directory = os.path.dirname(os.path.abspath(__file__))
|
|
| 229 |
# Set the model path to the same directory as the Python file
|
| 230 |
model_save_path = os.path.join(current_directory, 'model5k.pt')
|
| 231 |
model = GPT(GPTConfig())
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
model.to(device)
|
| 234 |
model.eval()
|
| 235 |
|
|
|
|
| 229 |
# Set the model path to the same directory as the Python file
|
| 230 |
model_save_path = os.path.join(current_directory, 'model5k.pt')
|
| 231 |
model = GPT(GPTConfig())
|
| 232 |
+
if device == 'cpu':
|
| 233 |
+
# Load the model on CPU if no GPU is available
|
| 234 |
+
model.load_state_dict(torch.load(model_save_path, map_location=torch.device('cpu')))
|
| 235 |
+
else:
|
| 236 |
+
# Load the model on GPU if available
|
| 237 |
+
model.load_state_dict(torch.load(model_save_path))
|
| 238 |
model.to(device)
|
| 239 |
model.eval()
|
| 240 |
|