Skip to content

vyomnagrani/hf-inference

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Hugging Face Model Inference Application

This application provides a flexible interface for loading and performing inference with any Hugging Face model. It supports various types of models including text, image, and audio models.

Installation

  1. Clone this repository
  2. Install the required dependencies:
pip install -r requirements.txt

Usage

Basic Usage

from model_inference import ModelInference

# Initialize a model for a specific task
model = ModelInference(
    model_name="distilbert-base-uncased-finetuned-sst-2-english",
    task="sentiment-analysis"
)

# Perform inference
result = model.infer("I love this application!")
print(result)

Supported Tasks

You can view all supported tasks using:

ModelInference.list_supported_tasks()

Example Tasks

  1. Text Classification:
classifier = ModelInference("distilbert-base-uncased-finetuned-sst-2-english", 
                          task="sentiment-analysis")
result = classifier.infer("I love using Hugging Face models!")
  1. Text Generation:
generator = ModelInference("gpt2", task="text-generation")
result = generator.infer("Once upon a time", 
                        max_length=50, 
                        num_return_sequences=1)
  1. Image Classification:
from PIL import Image
classifier = ModelInference("google/vit-base-patch16-224", 
                          task="image-classification")
image = Image.open("path/to/image.jpg")
result = classifier.infer(image)

Features

  • Automatic device selection (CPU/GPU)
  • Support for multiple model types
  • Error handling and logging
  • Flexible input handling
  • Easy-to-use interface

Requirements

  • Python 3.7+
  • PyTorch
  • Transformers
  • Other dependencies listed in requirements.txt

Note

Make sure you have enough system resources to load the models. Some large models may require significant RAM or GPU memory.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages