CoolFace
Apppublic

Nattylegit/ChatGPT-Plugins-in-Gradio

sourceHugging Facemitupdated 3y agoView on Hugging Face
1likes
App README

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

Steps to add new Plugins to your Gradio ChatGPT Chatbot

  1. 1.Acquire the API Endpoint
  2. 2.You need an API which you can query, and for this example let's consider using a text-to-speech demo hosted on Huggingface Spaces.
  3. 3.API Endpoint: https://gradio-neon-tts-plugin-coqui.hf.space/
  1. 1.Create a Function to Query the API
  2. 2.You can access any Gradio demo as an API via the Gradio Python Client.
python
    from gradio.client import Client

    def texttospeech(input_text):
        client = Client("https://gradio-neon-tts-plugin-coqui.hf.space/")
        result = client.predict(
            input_text,	# str  in 'Input' Textbox component
            "en",	    # str  in 'Language' Radio component
            api_name="/predict"
        )
        return result
  1. 1.Describe the Function to GPT-3.5
  2. 2.You need to describe your function to GPT3.5/4. This function definition will get passed to gpt and will suck up your token. GPT may or may not use this function based on user inputs later on.
  3. 3.You can either use the Gradio demo for converting any given function to the required JSON format for GPT-3.5.
  4. 4.Demo: Function to JSON
  5. 5.Or, you can create the dictionary object on your own. Note that, the correct format is super important here.
  6. 6.MAke sure to name your JSON object description as <function_name>_func.
python
    texttospeech_func = {
        "name": "texttospeech",
        "description": "generate speech from the given input text",
        "parameters": {
            "type": "object",
            "properties": {
                "input_text": {
                    "type": "string",
                    "description": "text that will be used to generate speech"
                }
            },
            "required": [
                "input_text"
            ]
        }
    }
  1. 1.Add Function and JSON Object Details
  2. 2.Add the function definition and description to the gpt_function_definitions.py file (simply copy and paste).
  3. 3.dict_plugin_functions is a dictionary of all available plugins. Add your plugin information to this dictionary in the required format.
python
    'texttospeech_func': {
        'dict': texttospeech_func,
        'func': texttospeech
    }
  1. 1.Update the Chatbot Layout
  2. 2.Go to the Blocks Chatbot layout and add a new checkbox for your plugin as:
python
    texttospeech = gr.Checkbox(label="πŸ“πŸ—£οΈText-To-Speech", value=False)
  • β€”Add the new checkbox component to your submit and click events for your chatbot and to the predict function accordingly.
  • β€”And also to the plugins list in predict
python
      plugins = [music_gen, stable_diff, image_cap, top_news, texttospeech]

Thats it! you are have added your own brand new CHATGPT Plugin for yourself. Go PLAY!!