Nattylegit/ChatGPT-Plugins-in-Gradio
1
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Steps to add new Plugins to your Gradio ChatGPT Chatbot
- Acquire the API Endpoint
- 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.
- API Endpoint: https://gradio-neon-tts-plugin-coqui.hf.space/
- 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- 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"
]
}
}- Add Function and JSON Object Details
- Add the function definition and description to the
gpt_function_definitions.pyfile (simply copy and paste). dict_plugin_functionsis a dictionary of all available plugins. Add your plugin information to this dictionary in the required format.
'texttospeech_func': {
'dict': texttospeech_func,
'func': texttospeech
}- 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
pluginslist inpredict
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!!
