|
|
import os |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
|
|
|
|
|
|
|
|
local_model_path = os.path.join(os.getcwd(), "fine_tuned_werther_model") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repo_id = "ajsbsd/distilgpt2-werther-finetuned" |
|
|
|
|
|
|
|
|
print(f"Loading model and tokenizer from local path: {local_model_path}...") |
|
|
try: |
|
|
model = AutoModelForCausalLM.from_pretrained(local_model_path) |
|
|
tokenizer = AutoTokenizer.from_pretrained(local_model_path) |
|
|
print("Model and tokenizer loaded successfully.") |
|
|
except Exception as e: |
|
|
print(f"Error loading local model/tokenizer: {e}") |
|
|
print("Please ensure the 'fine_tuned_werther_model' directory exists and contains the necessary files.") |
|
|
exit() |
|
|
|
|
|
|
|
|
print(f"\nUploading model and tokenizer to Hugging Face Hub: {repo_id}...") |
|
|
try: |
|
|
|
|
|
|
|
|
model.push_to_hub(repo_id, commit_message="Fine-tuned DistilGPT2 on The Sorrows of Young Werther") |
|
|
tokenizer.push_to_hub(repo_id, commit_message="Tokenizer for Werther fine-tuned model") |
|
|
print("Model and tokenizer uploaded successfully!") |
|
|
print(f"You can view your model here: https://huggingface.co/{repo_id}") |
|
|
|
|
|
except Exception as e: |
|
|
print(f"An error occurred during upload: {e}") |
|
|
print("Ensure you are logged in to Hugging Face Hub (`huggingface-cli login`) and have write access to the repository.") |
|
|
|