PHPackages                             swapinvidya/laravel-huggingface-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. swapinvidya/laravel-huggingface-client

ActiveLibrary[API Development](/categories/api)

swapinvidya/laravel-huggingface-client
======================================

A Laravel package for interacting with Hugging Face API

v1.0.10(1y ago)485MITPHPPHP &gt;=7.4

Since Nov 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/swapins/laravel-huggingface-client)[ Packagist](https://packagist.org/packages/swapinvidya/laravel-huggingface-client)[ RSS](/packages/swapinvidya-laravel-huggingface-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (12)Used By (0)

Laravel Hugging Face Client
===========================

[](#laravel-hugging-face-client)

**swapinvidya/laravel-huggingface-client** is a Laravel package that simplifies integration with the [Hugging Face API](https://huggingface.co/docs/api-inference). This package provides an easy way to interact with models for text generation, image creation, and other AI-powered features.

Features
--------

[](#features)

- **Text Generation**: Generate text using models like `gpt2` and `gpt-neo`.
- **Image Generation**: Create images based on text prompts using models such as `stable-diffusion`.
- **Custom Model Completions**: Use any available Hugging Face model for specialized tasks.
- **Seamless Integration**: Built for Laravel, with easy dependency injection.

Installation
------------

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

Run the following command in your Laravel project directory:

```
composer require swapinvidya/laravel-huggingface-client
```

### Step 2: Publish Configuration

[](#step-2-publish-configuration)

Publish the configuration file to customize your API key and other options:

```
php artisan vendor:publish --provider="Swapinvidya\HuggingFaceClient\HuggingFaceServiceProvider"
```

### Step 3: Set Up API Key

[](#step-3-set-up-api-key)

Add your Hugging Face API key to the `.env` file:

```
HUGGINGFACE_API_KEY=your_huggingface_api_key
```

Configuration
-------------

[](#configuration)

The configuration file will be published to `config/huggingface.php`. You can customize your API key and other settings there.

```
return [
    'api_key' => env('HUGGINGFACE_API_KEY'),
    'base_uri' => 'https://api-inference.huggingface.co/',
];
```

Usage
-----

[](#usage)

Inject the `HuggingFaceClient` in your controllers or services to use its capabilities.

### Example: Generate Text

[](#example-generate-text)

```
use Swapinvidya\HuggingFaceClient\HuggingFaceClient;

public function generateText(HuggingFaceClient $huggingFaceClient)
{
    $response = $huggingFaceClient->generateText('gpt2', 'Write a short story about a hero.');
    return response()->json($response);
}
```

### Example: Generate Image

[](#example-generate-image)

```
public function generateImage(HuggingFaceClient $huggingFaceClient)
{
    $response = $huggingFaceClient->generateImage('stable-diffusion-v1', 'A futuristic city with flying cars.');
    return response()->json($response);
}
```

### Example: Custom Model Completion

[](#example-custom-model-completion)

```
public function generateCompletion(HuggingFaceClient $huggingFaceClient)
{
    $params = [
        'inputs' => 'Explain the theory of relativity in simple terms.',
        'parameters' => [
            'temperature' => 0.7,
            'max_new_tokens' => 200,
        ],
    ];
    $response = $huggingFaceClient->generateCompletion('gpt-neo', $params);
    return response()->json($response);
}
```

Available Methods
-----------------

[](#available-methods)

### `generateText($model, $input)`

[](#generatetextmodel-input)

Generates text output using the specified model.

- **`$model`**: The model to use (e.g., `gpt2`, `gpt-neo`).
- **`$input`**: The text input/prompt for the model.

### `generateImage($model, $input)`

[](#generateimagemodel-input)

Creates an image based on a text prompt.

- **`$model`**: The image generation model (e.g., `stable-diffusion`).
- **`$input`**: The text prompt describing the image.

### `generateCompletion($model, $params)`

[](#generatecompletionmodel-params)

Generates a completion response with custom parameters.

- **`$model`**: The model to use (e.g., `gpt-neo`, `opt`).
- **`$params`**: Array of parameters including `inputs` and optional model settings like `temperature` and `max_new_tokens`.

Error Handling
--------------

[](#error-handling)

The client will return error information in the response if a request fails:

```
$response = $huggingFaceClient->generateText('gpt2', 'Hello world');

if (isset($response['error'])) {
    // Handle the error
    return response()->json(['error' => $response['error']], 500);
}

return response()->json($response);
```

Testing
-------

[](#testing)

To test your package locally, you can link it to a Laravel project using:

```
composer config repositories.local '{"type": "path", "url": "../path/to/laravel-huggingface-client"}'
composer require swapinvidya/laravel-huggingface-client:@dev
```

Contributing
------------

[](#contributing)

Feel free to open issues or submit pull requests for improvements and new features.

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

---

*Developed by [swapinvidya](https://github.com/swapinvidya)*

```

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

11

Last Release

549d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9073179ab0756e23c533eab7e29a07f57e123238d3f6e0b7dcb0aa0cb66adb8c?d=identicon)[swapins](/maintainers/swapins)

### Embed Badge

![Health badge](/badges/swapinvidya-laravel-huggingface-client/health.svg)

```
[![Health](https://phpackages.com/badges/swapinvidya-laravel-huggingface-client/health.svg)](https://phpackages.com/packages/swapinvidya-laravel-huggingface-client)
```

###  Alternatives

[skagarwal/google-places-api

Google Places Api

1913.0M8](/packages/skagarwal-google-places-api)[dcblogdev/laravel-microsoft-graph

A Laravel Microsoft Graph API (Office365) package

168285.5k1](/packages/dcblogdev-laravel-microsoft-graph)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[grantholle/powerschool-api

A Laravel package to make interacting with PowerSchool less painful.

1715.6k1](/packages/grantholle-powerschool-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
