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!'))
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
