Update app.py
Browse files
app.py
CHANGED
|
@@ -12,15 +12,18 @@ max_seq_length = 4096
|
|
| 12 |
dtype = None
|
| 13 |
load_in_4bit = True
|
| 14 |
hf_token = os.getenv("HF_TOKEN")
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
print("Starting model and tokenizer loading...")
|
| 20 |
|
| 21 |
# Load the model and tokenizer
|
| 22 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 23 |
-
model_name=
|
| 24 |
max_seq_length=max_seq_length,
|
| 25 |
dtype=dtype,
|
| 26 |
load_in_4bit=load_in_4bit,
|
|
@@ -135,6 +138,11 @@ print("Starting training...")
|
|
| 135 |
trainer_stats = trainer.train()
|
| 136 |
print("Training completed.")
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
print("Saving the trained model...")
|
| 139 |
model.save_pretrained_merged("model", tokenizer, save_method="merged_16bit")
|
| 140 |
print("Model saved successfully.")
|
|
@@ -148,5 +156,5 @@ model.push_to_hub_merged(
|
|
| 148 |
)
|
| 149 |
print("Model pushed to hub successfully.")
|
| 150 |
|
| 151 |
-
api =
|
| 152 |
-
api.
|
|
|
|
| 12 |
dtype = None
|
| 13 |
load_in_4bit = True
|
| 14 |
hf_token = os.getenv("HF_TOKEN")
|
| 15 |
+
current_num = os.getenv("NUM")
|
| 16 |
|
| 17 |
+
print(f"stage ${current_num}")
|
| 18 |
+
|
| 19 |
+
api = HfApi(token=hf_token)
|
| 20 |
+
models = f"dad1909/CyberSentinel-{current_num}"
|
| 21 |
|
| 22 |
print("Starting model and tokenizer loading...")
|
| 23 |
|
| 24 |
# Load the model and tokenizer
|
| 25 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 26 |
+
model_name=models,
|
| 27 |
max_seq_length=max_seq_length,
|
| 28 |
dtype=dtype,
|
| 29 |
load_in_4bit=load_in_4bit,
|
|
|
|
| 138 |
trainer_stats = trainer.train()
|
| 139 |
print("Training completed.")
|
| 140 |
|
| 141 |
+
num = int(current_num)
|
| 142 |
+
num += 1
|
| 143 |
+
|
| 144 |
+
uploads_models = f"CyberSentinel-{str(num)}"
|
| 145 |
+
|
| 146 |
print("Saving the trained model...")
|
| 147 |
model.save_pretrained_merged("model", tokenizer, save_method="merged_16bit")
|
| 148 |
print("Model saved successfully.")
|
|
|
|
| 156 |
)
|
| 157 |
print("Model pushed to hub successfully.")
|
| 158 |
|
| 159 |
+
api.delete_space_variable(repo_id="dad1909/CyberCode", key="NUM")
|
| 160 |
+
api.add_space_variable(repo_id="dad1909/CyberCode", key="NUM", value=str(num))
|