Python / Python Modern Generative AI and Agents Interview Questions
What is the Hugging Face Hub and how do you push a trained model to share it?
The Hugging Face Hub is a platform hosting over 900,000 models, 200,000 datasets, and 300,000 Spaces (interactive apps). Every model on the Hub has a model card (README.md) documenting its architecture, training data, performance, intended uses, and limitations — following a community standard for responsible model sharing.
The huggingface_hub library and the push_to_hub method in Transformers make it trivial to upload models and interact with the Hub's API — browsing, downloading, and uploading models, datasets, and tokenizers.
from transformers import AutoModelForSequenceClassification, AutoTokenizer from huggingface_hub import HfApi, login # Authenticate (or set HF_TOKEN env var) login(token='hf_....') # get token from huggingface.co/settings/tokens # Load a fine-tuned local model and push to Hub model = AutoModelForSequenceClassification.from_pretrained('./my-model') tokenizer = AutoTokenizer.from_pretrained('./my-model') # Push to Hub (creates repo if it doesn't exist) model.push_to_hub('your-username/my-sentiment-classifier') tokenizer.push_to_hub('your-username/my-sentiment-classifier') # ââ Interact with Hub API directly api = HfApi() # List models by task or keyword models = api.list_models(task='text-classification', sort='downloads', limit=5) for m in models: print(m.modelId, m.downloads) # Download a specific file from a repo api.hf_hub_download( repo_id='bert-base-uncased', filename='config.json', local_dir='./downloaded' ) # ââ Create a Space (Gradio demo) api.create_repo( repo_id='your-username/my-demo', repo_type='space', space_sdk='gradio', ) # ââ Quick inference with pipeline from Hub from transformers import pipeline clf = pipeline('text-classification', model='your-username/my-sentiment-classifier') print(clf('This product is amazing!'))
More Related questions...