pikto's picture
Duplicate from ysharma/ChatGPT-Plugins-in-Gradio
fb597a7

A newer version of the Gradio SDK is available: 5.5.0

Upgrade
metadata
title: ChatGPT Plugins In Gradio
emoji: 💻
colorFrom: green
colorTo: gray
sdk: gradio
sdk_version: 3.35.2
app_file: app.py
pinned: true
license: mit
duplicated_from: ysharma/ChatGPT-Plugins-in-Gradio

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. Acquire the API Endpoint

  2. Create a Function to Query the API

    • You can access any Gradio demo as an API via the Gradio Python Client.
    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
    
  3. Describe the Function to GPT-3.5

    • 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.
    • You can either use the Gradio demo for converting any given function to the required JSON format for GPT-3.5.
      • Demo: Function to JSON
      • Or, you can create the dictionary object on your own. Note that, the correct format is super important here.
    • MAke sure to name your JSON object description as <function_name>_func.
    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"
            ]
        }
    }
    
  4. Add Function and JSON Object Details

    • Add the function definition and description to the gpt_function_definitions.py file (simply copy and paste).
    • dict_plugin_functions is a dictionary of all available plugins. Add your plugin information to this dictionary in the required format.
    'texttospeech_func': {
        'dict': texttospeech_func,
        'func': texttospeech
    }
    
  5. Update the Chatbot Layout

    • Go to the Blocks Chatbot layout and add a new checkbox for your plugin as:
    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
      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!!