Giter Site home page Giter Site logo

unity-api's Introduction

Hugging Face API for Unity ๐Ÿค—

This Unity package provides an easy-to-use integration for the Hugging Face Inference API, allowing developers to access and use Hugging Face AI models within their Unity projects.

Table of Contents

  1. Installation
  2. Usage
  3. Tasks
  4. Support

Installation

Via Git URL

  1. Open the Unity project you want to add the package to.
  2. Go to "Window" > "Package Manager" to open the Package Manager.
  3. Click the "+" in the upper left hand corner and select "Add package from git URL".
  4. Enter the URL of this repository and click "Add": https://github.com/huggingface/unity-api.git

Usage

Configuration

In the Hugging Face Website:

  1. Generate an API key in https://huggingface.co/settings/tokens, we **advise you to create a Fine-Grained Token.

  2. When the API key is created click on Set Permissions

Hugging Face Token Step 2

  1. Authorize Inference with this API key

Hugging Face Token Step 3

After installation, the Hugging Face API wizard should open. If not, open it by clicking "Window" > "Hugging Face API Wizard".

  1. Test the API key.

  2. Optionally, update the endpoints to use different models.

Try our tutorial

To help you getting started, we wrote a tutorial where you create a robot agent that understands text orders and executes them.

The tutorial ๐Ÿ‘‰ https://thomassimonini.substack.com/p/building-a-smart-robot-ai-using-hugging

The demo ๐Ÿ‘‰ https://huggingface.co/spaces/ThomasSimonini/SmartRobot

Jammo Robot

Example Scene

To try the included example scene, follow these steps:

  1. Click "Install Examples" in the Hugging Face API Wizard to copy the example files into your project.
  2. Navigate to the "Hugging Face API" > "Examples" > "Scenes" folder in your project.
  3. Open the "ConversationExample" scene.
  4. If prompted by the TMP Importer, click "Import TMP Essentials".
  5. Press "Play" to run the example. You should be able to use the UI to interact with the model.

API Usage in Scripts

The package includes a HuggingFaceAPI class that you can use from your scripts.

  1. Import the HuggingFace.API namespace in your script.
  2. Call the API method for the task you want.
using HuggingFace.API;

HuggingFaceAPI.TextToImage("a cat in a hat", result => {
    // Do something with the result, which in this case is a Texture2D
}, error => {
    // Handle errors
    Debug.LogError(error);
});

For a more advanced scripting example, refer to the included example scripts.

Tasks

Task Status
Conversation โœ…
Text Generation โœ…
Text to Image โœ…
Text Classification โœ…
Zero Shot Text Classification โœ…
Question Answering โœ…
Translation โœ…
Summarization โœ…
Sentence Similarity โœ…
Speech Recognition โœ…

Support

If you encounter issues or have questions about the package, open an issue on the repository.

unity-api's People

Contributors

dylanebert avatar simoninithomas avatar stephenhodgson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-api's Issues

Multiple models

Really good job!
Is it possible to use more than one model for each task simultaneously?
Thank you.

[FEATURE REQUEST] Run Models Locally

Hi,
Thanks for making the great tutorial (on Substack)!
Might it be possible to allow users to run models locally (instead of using the API), and bundle the models into their apps? This would be great for offline usage.
Thank you!

[BUG] Conversation API deprecation

Conversation API is now deprecated on the hub, since it's the same as Text Generation.

The Conversation task should be revised to be a wrapper around text-generation, to avoid breaking existing demos.

[Documentation] Getting started instructions and Access Tokens

The Usage > Configuration section in the README says that to generate an API key, people need to go to https://huggingface.co/settings/profile

However, there's no option to generate API keys there, the correct link to generate the access tokens is: https://huggingface.co/settings/tokens

On that note, I suggest you rename the API key (in the README and the Hugging Face API Wizard) to Access Tokens. There are also the SSH and GPG keys which might yield confusion.

[BUG] Getting internal server errors when trying to connect to hugging face models

Describe the bug
Getting the following errors:
Attempted request to https://api-inference.huggingface.co/models/distilbert-base-cased-distilled-squad failed: HTTP/1.1 503 Service Unavailable - {"error":"Model distilbert-base-cased-distilled-squad is currently loading","estimated_time":20.0}
UnityEngine.Debug:LogWarning (object)
HuggingFace.API.APIClient/d__1:MoveNext () (at ./Library/PackageCache/com.huggingface.api@cb0acecbe2/Runtime/Implementations/APIClient.cs:73)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

To Reproduce
Steps to reproduce the behavior:

  1. Follow tutorial to install HuggingFace to Unity
  2. Try to load the example code to use "HuggingFaceAPI.QuestionAnswering(inputText, OnSuccess, OnError, content);" function.
  3. Set the timeout in the Huggingface setting window to be more than 3 seconds (it will timeout if you don't).
  4. Click run in Unity editor
  5. See error

Desktop (please complete the following information):

  • OS: Windows 11
  • Unity 2022.3.6f1

Additional context
Add any other context about the problem here.

will not run on unity 2022 lts or 2022.3.0f1

Describe the bug
Whenever I try to run the example scenes the following error occurs:

"NullReferenceException: Object reference not set to an instance of an object
HuggingFace.API.Editor.HuggingFaceAPIWizard.OnGUI () (at ./Library/PackageCache/com.huggingface.api@cb0acecbe2/Editor/HuggingFaceAPIWizard.cs:60)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition) (at /Users/bokken/build/output/unity/unity/Editor/Mono/HostView.cs:512)
UnityEditor.DockArea.DrawView (UnityEngine.Rect dockAreaRect) (at /Users/bokken/build/output/unity/unity/Editor/Mono/GUI/DockArea.cs:386)
UnityEditor.DockArea.OldOnGUI () (at /Users/bokken/build/output/unity/unity/Editor/Mono/GUI/DockArea.cs:377)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/IMGUIContainer.cs:355)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:190)"

Looks like the hugging face api for unity only works on Unity 2020.3.48f1? But I have to work on 2022 LTS release...

iMac Intel with Ventura 13.6

Thanks for any help!

Android support

Great repo! My question is - does it work on Android?

I did some research but couldn't find much - except for some comments on YouTube that speech recognition doesn't really work on Android ("when i export to an a Android Device the text always is "you", no matter what did i say. I don't know if needs another configuration because in the unity editor works fine").

Could you please clarify?

Thank you!

[FEATURE REQUEST] Implement AudioClassification Task for CLAP Models

Is your feature request related to a problem? Please describe.
Currently, the Unity API for Hugging Face does not support the AudioClassification task, particularly for CLAP models. This limits the potential for developing interactive applications and games that can utilize audio recognition capabilities in Unity.

Describe the solution you'd like
I would like to see the implementation of the AudioClassification task in the Hugging Face Unity API, with support for CLAP models, especially the 'laion/clap-htsat-unfused' model (https://huggingface.co/laion/clap-htsat-unfused). This would enable Unity developers to integrate advanced audio classification features into their applications, enhancing interactivity and user engagement.

Additional context
The CLAP model (https://huggingface.co/docs/transformers/model_doc/clap) has significant potential for applications in game development and interactive experiences where audio input can trigger specific actions or responses. Implementing this feature in the Unity API would greatly benefit developers looking to explore innovative audio-based interactions in their projects.

[Bug] Package should not throw error for missing config

When loading the package for the first time it should not throw an error about missing config file.

Instead, either pop up a dialog or change the log from error to warning.

In either case, giving the user time to create/configure should be done before presenting with error message.

[Bug] Missing assembly definitions for examples

Script 'Packages/com.huggingface.api/Examples/Scripts/ConversationExample.cs' will not be compiled because it exists outside the Assets folder and does not to belong to any assembly definition file.
Script 'Packages/com.huggingface.api/Examples/Scripts/TextToImageExample.cs' will not be compiled because it exists outside the Assets folder and does not to belong to any assembly definition file.

[BUG] Task AutomaticSpeechRecognition not found.

Describe the bug
I have successfully integrated the API in to the unity editor. When I get a release build on IOS, I am receiving the error "Task AutomaticSpeechRecognition not found."

To Reproduce
Steps to reproduce the behavior:
1- Run on iOS device.

  • OS: iPhone 13 Pro running on iOS 16
HuggingFaceAPI.AutomaticSpeechRecognition(_bytesRecorded, response => {
               Debug.Log($"Message is = {response}");
               voiceChatPrompt.Show(response);
               IsWaitingApiResult = false;
           }, error => {
              // Task AutomaticSpeechRecognition not found
               Debug.LogError(error);
               IsWaitingApiResult = false;
           });

Future improvements

This issue lists the future improvements we can make based on user's feedback:
โœ… #4

  • Set parameters and expose them via config file.
  • Specifying language for compatible models.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.