Spaces:
Sleeping
Sleeping
LorenzoBioinfo
commited on
Commit
·
5753b42
1
Parent(s):
70f9b6b
Add deploy HF
Browse files- .github/workflows/ci.yml +2 -0
- src/train_model.py +8 -0
.github/workflows/ci.yml
CHANGED
|
@@ -24,6 +24,8 @@ jobs:
|
|
| 24 |
python -m pip install --upgrade pip
|
| 25 |
pip install -r requirements.txt
|
| 26 |
pip install flake8 pytest
|
|
|
|
|
|
|
| 27 |
|
| 28 |
- name: Cache Hugging Face and datasets
|
| 29 |
uses: actions/cache@v4
|
|
|
|
| 24 |
python -m pip install --upgrade pip
|
| 25 |
pip install -r requirements.txt
|
| 26 |
pip install flake8 pytest
|
| 27 |
+
- name: Set HuggingFace token
|
| 28 |
+
run: echo "${{ secrets.HFREPO }}" > ~/.hf_token
|
| 29 |
|
| 30 |
- name: Cache Hugging Face and datasets
|
| 31 |
uses: actions/cache@v4
|
src/train_model.py
CHANGED
|
@@ -8,10 +8,17 @@ from datasets import load_from_disk,concatenate_datasets
|
|
| 8 |
import evaluate
|
| 9 |
import numpy as np
|
| 10 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
MODEL_NAME = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
| 13 |
DATA_PATH = "data/processed/tweet_eval_tokenized"
|
| 14 |
OUTPUT_DIR = "models/sentiment_model"
|
|
|
|
| 15 |
|
| 16 |
def compute_metrics(eval_pred):
|
| 17 |
"""Calcola metriche standard: accuracy e F1."""
|
|
@@ -67,6 +74,7 @@ def train_model(additional_data=None,sample_train_size=1000, sample_eval_size=30
|
|
| 67 |
os.makedirs(output_dir, exist_ok=True)
|
| 68 |
trainer.save_model(output_dir)
|
| 69 |
print(f"Modello salvato in: {OUTPUT_DIR}")
|
|
|
|
| 70 |
|
| 71 |
if __name__ == "__main__":
|
| 72 |
train_model()
|
|
|
|
| 8 |
import evaluate
|
| 9 |
import numpy as np
|
| 10 |
import os
|
| 11 |
+
from huggingface_hub import HfApi
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
hf_token = os.environ["HF_TOKEN"]
|
| 15 |
+
|
| 16 |
+
#
|
| 17 |
|
| 18 |
MODEL_NAME = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
| 19 |
DATA_PATH = "data/processed/tweet_eval_tokenized"
|
| 20 |
OUTPUT_DIR = "models/sentiment_model"
|
| 21 |
+
HF_REPO = "Lordemarco/SentimentAnalysis"
|
| 22 |
|
| 23 |
def compute_metrics(eval_pred):
|
| 24 |
"""Calcola metriche standard: accuracy e F1."""
|
|
|
|
| 74 |
os.makedirs(output_dir, exist_ok=True)
|
| 75 |
trainer.save_model(output_dir)
|
| 76 |
print(f"Modello salvato in: {OUTPUT_DIR}")
|
| 77 |
+
trainer.push_to_hub("Lordemarco/SentimentAnalysis", use_auth_token=os.environ["HF_TOKEN"])
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
| 80 |
train_model()
|