|

|  How to Integrate Hugging Face with GitHub

How to Integrate Hugging Face with GitHub

January 24, 2025

Master seamless integration of Hugging Face and GitHub with this concise guide, enhancing your AI project workflows and collaboration effortlessly.

How to Connect Hugging Face to GitHub: a Simple Guide

 

Setting Up Your Environment

 

  • Ensure you have a GitHub account. If not, create one at GitHub.
  •  

  • Sign up for a Hugging Face account at Hugging Face.
  •  

  • Install Git on your system if not already installed: Download Git.

 

git --version

 

Creating a Repository on GitHub

 

  • Log in to your GitHub account and navigate to the "Repositories" tab.
  •  

  • Click on "New" to create a new repository.
  •  

  • Provide a repository name and description, and decide if it should be public or private.
  •  

  • Click "Create repository" to finalize.

 

Cloning Your GitHub Repository Locally

 

  • Navigate to your repository page on GitHub and copy the repository URL.
  •  

  • Open a terminal and run the following command to clone the repository:

 

git clone <Your-GitHub-Repo-URL>

 

Setting Up Hugging Face Transformers Library

 

  • Ensure Python is installed. You can verify or download it from python.org.
  •  

  • Install the Hugging Face Transformers library:

 

pip install transformers

 

Creating a Sample Model Script

 

  • Navigate to your cloned repository directory:

 

cd <Your-Repo-Name>

 

  • Create a new file named `model_script.py` and add the following code to load a pre-trained model from Hugging Face:

 

from transformers import pipeline

classifier = pipeline('sentiment-analysis')

result = classifier('I love using Hugging Face!')
print(result)

 

Committing and Pushing Changes to GitHub

 

  • Stage your changes:

 

git add model_script.py

 

  • Commit your changes with a descriptive message:

 

git commit -m "Add sentiment analysis script using Hugging Face"

 

  • Push your changes to the GitHub repository:

 

git push origin main

 

Integrating Hugging Face Inference API

 

  • Navigate to your Hugging Face account and create a new token for authorization.
  •  

  • Save this token securely for API usage.
  •  

  • Update your script to use Hugging Face's Inference API:

 

import requests

API_URL = "https://api-inference.huggingface.co/models/distilbert-base-uncased-finetuned-sst-2-english"
headers = {"Authorization": "Bearer <Your-Hugging-Face-Token>"}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()

data = query({"inputs": "I love using Hugging Face!"})
print(data)

 

Final Commit and Push

 

  • Stage, commit, and push your changes with an appropriate message:

 

git add model_script.py
git commit -m "Integrate Hugging Face Inference API"
git push origin main

 

Verifying Integration

 

  • Check your GitHub repository to verify the presence of your recent commits and files.
  •  

  • Run the script locally to ensure it integrates properly with both your local setup and the Hugging Face API.

 

This step-by-step guide provides a thorough integration process between Hugging Face and GitHub, covering setting up the environment, using the Transformers library, and leveraging the Inference API. Feel free to expand upon this workflow according to your specific needs and use cases.

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi Dev Kit 2.

How to Use Hugging Face with GitHub: Usecases

 

Integrating Hugging Face Models with GitHub Actions

 

  • Host and version your machine learning models using Hugging Face's model repository, which allows seamless management and deployment of models.
  •  

  • Create a GitHub repository to store your application's source code and any relevant scripts for integrating and using the Hugging Face models.

 

git init
git add .
git commit -m "Initial commit with application source code"

 

Automate Model Deployment with GitHub Actions

 

  • Set up a GitHub Actions workflow file in your repository to automate the process of testing and deploying your application with the Hugging Face model.
  •  

  • Utilize Hugging Face's inference endpoint to directly pull the model for inference during the automated workflow, reducing the need for manual updates.

 

name: Deploy Application

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.x'
      
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      
      - name: Run Deploy Script
        run: python deploy_with_huggingface.py

 

Monitor and Improve the Workflow

 

  • Regularly review the logs and feedback from GitHub Actions runs to identify improvements in the deployment and integration processes.
  •  

  • Collaborate and manage the development process efficiently through GitHub Issues and Projects, aligning your model development lifecycle with your application development timeline.

 

# Review logs using the GitHub Actions console
# Discuss model performance improvements in GitHub Issues

 

 

Collaborative Model Training and Deployment

 

  • Utilize Hugging Face's `datasets` library to load and preprocess datasets directly within your model training scripts, allowing for efficient collaborative development.
  •  

  • Store your training scripts and configurations in a shared GitHub repository, enabling multiple collaborators to contribute to the model training process efficiently.

 

from datasets import load_dataset

dataset = load_dataset('imdb')

 

Version Control with GitHub

 

  • Leverage GitHub's version control capabilities to track changes made to your Hugging Face model training and experimentation scripts.
  •  

  • Create branches for different experimentations or model improvements, and merge successful changes to the main branch for stable deployments.

 

git checkout -b improve-model

 

Continuous Integration for Model Quality

 

  • Set up continuous integration workflows using GitHub Actions to automatically test model changes and ensure high-quality outputs with each commit.
  •  

  • Use these workflows to run unit tests, data validation checks, and model evaluation scripts to maintain a robust development lifecycle.

 

name: Model Testing Workflow

on: [pull_request]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.x'
      
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      
      - name: Run Tests
        run: pytest tests/

 

Deploy and Use Trained Models

 

  • Deploy trained models on Hugging Face's model hub for easy access and integration into your applications, streamlining model usage across different platforms.
  •  

  • Document the model usage in the GitHub repository to guide fellow developers on how to efficiently use and incorporate the models into their solutions.

 

```md

Access models from Hugging Face Model Hub

Follow integration guidelines in README.md

```

 

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

Order Friend Dev Kit

Open-source AI wearable
Build using the power of recall

Order Now

Troubleshooting Hugging Face and GitHub Integration

How to deploy a Hugging Face model to GitHub Pages?

 

Deploying a Hugging Face Model

 

  • **Export** the trained Hugging Face model to a format suitable for web apps, such as ONNX for lightweight applications.
  •  

  • **Create** a basic HTML and JavaScript interface to load and interact with your model. Use the Hugging Face's `transformers` JavaScript library if needed.

 


import { pipeline } from '@huggingface/transformers';  
const classifier = await pipeline('text-classification'); 
classifier('Your text here');

 

Deploy to GitHub Pages

 

  • **Initialize** a GitHub repo if not already done and push your HTML/JavaScript files.
  •  

  • **Enable** GitHub Pages in the repo settings navigating to "Settings" > "Pages" and selecting the branch and folder (usually `main` branch and `/root`).

 

git init  
git add .  
git commit -m "Deploy model"  
git push origin main  

 

  • **Access** your deployed model page via the URL provided by GitHub Pages, typically `https://username.github.io/repo-name`.

 

Why is my Hugging Face model link not working in GitHub README?

 

Common Issues

 

  • The link may be incorrect. Ensure you use the accurate URL structure: https://huggingface.co/username/modelname.
  •  

  • If you have a private model, it's inaccessible without authentication. Consider making it public or add authentication steps in your instructions.

 

Markdown Syntax

 

  • Verify the correct Markdown syntax in your README. Use the format: [Model Name](https://huggingface.co/username/modelname).
  •  

  • Check for typos or syntax errors that might break the link.

 

URL Encoding

 

  • Ensure all special characters in the URL, like spaces, are properly encoded.

 


[My Hugging Face Model](https://huggingface.co/username/model%20name)

 

Troubleshooting Steps

 

  • Test the link outside GitHub to ensure it resolves correctly. Paste it in a browser to confirm it's working.
  •  

  • Check GitHub's markdown rendering: preview the Markdown to see if the link is clickable.

 

How can I automate model versioning from GitHub to Hugging Face Hub?

 

Integrate GitHub Actions

 

  • Create a workflow `.yml` file in `.github/workflows` to pull the latest changes and train your model.
  • Ensure the workflow triggers on `push` and `pull_request` events.

 

Install Hugging Face CLI

 

  • Add the Hugging Face tokens as GitHub secrets for authentication.
  • Install the Hugging Face CLI using the command:

 

pip install huggingface_hub

 

Automate Versioning in Workflow

 

  • Use the Hugging Face CLI commands in your GitHub Actions pipeline:

 

hf_cli login --token ${{ secrets.HF_TOKEN }}

 

  • Push model to Hugging Face Hub with:

 

hf_cli repo create my-model --type model
git remote add hf https://huggingface.co/my-username/my-model
git push hf main

 

Trigger Based on Model Changes

 

  • Configure specific paths in `on.push.paths` to run the workflow only when relevant model files change.

 

 

Don’t let questions slow you down—experience true productivity with the AI Necklace. With Omi, you can have the power of AI wherever you go—summarize ideas, get reminders, and prep for your next project effortlessly.

Order Now

Join the #1 open-source AI wearable community

Build faster and better with 3900+ community members on Omi Discord

Participate in hackathons to expand the Omi platform and win prizes

Participate in hackathons to expand the Omi platform and win prizes

Get cash bounties, free Omi devices and priority access by taking part in community activities

Join our Discord → 

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded

OMI NECKLACE: DEV KIT
Order your Omi Dev Kit 2 now and create your use cases

Omi Dev Kit 2

Endless customization

OMI DEV KIT 2

$69.99

Make your life more fun with your AI wearable clone. It gives you thoughts, personalized feedback and becomes your second brain to discuss your thoughts and feelings. Available on iOS and Android.

Your Omi will seamlessly sync with your existing omi persona, giving you a full clone of yourself – with limitless potential for use cases:

  • Real-time conversation transcription and processing;
  • Develop your own use cases for fun and productivity;
  • Hundreds of community apps to make use of your Omi Persona and conversations.

Learn more

Omi Dev Kit 2: build at a new level

Key Specs

OMI DEV KIT

OMI DEV KIT 2

Microphone

Yes

Yes

Battery

4 days (250mAH)

2 days (250mAH)

On-board memory (works without phone)

No

Yes

Speaker

No

Yes

Programmable button

No

Yes

Estimated Delivery 

-

1 week

What people say

“Helping with MEMORY,

COMMUNICATION

with business/life partner,

capturing IDEAS, and solving for

a hearing CHALLENGE."

Nathan Sudds

“I wish I had this device

last summer

to RECORD

A CONVERSATION."

Chris Y.

“Fixed my ADHD and

helped me stay

organized."

David Nigh

OMI NECKLACE: DEV KIT
Take your brain to the next level

LATEST NEWS
Follow and be first in the know

Latest news
FOLLOW AND BE FIRST IN THE KNOW

thought to action

team@basedhardware.com

company

careers

events

invest

privacy

products

omi

omi dev kit

personas

resources

apps

bounties

affiliate

docs

github

help