Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,7 +51,10 @@ def train_batch(dataloader):
|
|
| 51 |
|
| 52 |
elapsed_time = time.time() - start_time
|
| 53 |
if elapsed_time > 1: # Dừng trước 59 giây để đảm bảo không vượt hạn ngạch
|
|
|
|
|
|
|
| 54 |
torch.save(model.state_dict(), "./checkpoint/model.pt")
|
|
|
|
| 55 |
return False, "Checkpoint saved. Training paused."
|
| 56 |
|
| 57 |
return True, "Batch training completed."
|
|
@@ -85,7 +88,9 @@ def train_step(file=None):
|
|
| 85 |
|
| 86 |
start_idx = end_idx
|
| 87 |
time.sleep(2) # Nghỉ 2 giây giữa các phiên huấn luyện
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
torch.save(model.state_dict(), "./checkpoint/model.pt")
|
| 90 |
return "Training completed and model saved."
|
| 91 |
|
|
|
|
| 51 |
|
| 52 |
elapsed_time = time.time() - start_time
|
| 53 |
if elapsed_time > 1: # Dừng trước 59 giây để đảm bảo không vượt hạn ngạch
|
| 54 |
+
if not os.path.exists('./checkpoint'):
|
| 55 |
+
os.makedirs('./checkpoint')
|
| 56 |
torch.save(model.state_dict(), "./checkpoint/model.pt")
|
| 57 |
+
|
| 58 |
return False, "Checkpoint saved. Training paused."
|
| 59 |
|
| 60 |
return True, "Batch training completed."
|
|
|
|
| 88 |
|
| 89 |
start_idx = end_idx
|
| 90 |
time.sleep(2) # Nghỉ 2 giây giữa các phiên huấn luyện
|
| 91 |
+
|
| 92 |
+
if not os.path.exists('./checkpoint'):
|
| 93 |
+
os.makedirs('./checkpoint')
|
| 94 |
torch.save(model.state_dict(), "./checkpoint/model.pt")
|
| 95 |
return "Training completed and model saved."
|
| 96 |
|