Update app.py
Browse files
app.py
CHANGED
@@ -26,6 +26,76 @@ available_function_defns = {
|
|
26 |
key.split('_func')[0]: value['func']
|
27 |
for key, value in dict_plugin_functions.items()
|
28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
# managing conversation with Plugins
|
31 |
def run_conversation(user_input, function_call_decision):
|
|
|
26 |
key.split('_func')[0]: value['func']
|
27 |
for key, value in dict_plugin_functions.items()
|
28 |
}
|
29 |
+
add_plugin_steps = """## Steps to add new Plugins to your Gradio ChatGPT Chatbot
|
30 |
+
Do you want to open this information in a separate tab instead? - <a href="https://huggingface.co/spaces/ysharma/ChatGPT-Plugins-in-Gradio/blob/main/README.md" target="_blank">Click here</a>.
|
31 |
+
|
32 |
+
1. **Acquire the API Endpoint**
|
33 |
+
- 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.
|
34 |
+
- **API Endpoint**: [https://gradio-neon-tts-plugin-coqui.hf.space/](https://gradio-neon-tts-plugin-coqui.hf.space/)
|
35 |
+
|
36 |
+
2. **Create a Function to Query the API**
|
37 |
+
- You can access any Gradio demo as an API via the Gradio Python Client.
|
38 |
+
```python
|
39 |
+
from gradio.client import Client
|
40 |
+
|
41 |
+
def texttospeech(input_text):
|
42 |
+
client = Client("https://gradio-neon-tts-plugin-coqui.hf.space/")
|
43 |
+
result = client.predict(
|
44 |
+
input_text, # str in 'Input' Textbox component
|
45 |
+
"en", # str in 'Language' Radio component
|
46 |
+
api_name="/predict"
|
47 |
+
)
|
48 |
+
return result
|
49 |
+
```
|
50 |
+
|
51 |
+
3. **Describe the Function to GPT-3.5**
|
52 |
+
- 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.
|
53 |
+
- You can either use the Gradio demo for converting any given function to the required JSON format for GPT-3.5.
|
54 |
+
- Demo: [Function to JSON](https://huggingface.co/spaces/ysharma/function-to-JSON)
|
55 |
+
- Or, you can create the dictionary object on your own. Note that, the correct format is super important here.
|
56 |
+
- MAke sure to name your JSON object description as `<function_name>_func`.
|
57 |
+
```python
|
58 |
+
texttospeech_func = {
|
59 |
+
"name": "texttospeech",
|
60 |
+
"description": "generate speech from the given input text",
|
61 |
+
"parameters": {
|
62 |
+
"type": "object",
|
63 |
+
"properties": {
|
64 |
+
"input_text": {
|
65 |
+
"type": "string",
|
66 |
+
"description": "text that will be used to generate speech"
|
67 |
+
}
|
68 |
+
},
|
69 |
+
"required": [
|
70 |
+
"input_text"
|
71 |
+
]
|
72 |
+
}
|
73 |
+
}
|
74 |
+
```
|
75 |
+
|
76 |
+
4. **Add Function and JSON Object Details**
|
77 |
+
- Add the function definition and description to the `gpt_function_definitions.py` file (simply copy and paste).
|
78 |
+
- `dict_plugin_functions` is a dictionary of all available plugins. Add your plugin information to this dictionary in the required format.
|
79 |
+
```python
|
80 |
+
'texttospeech_func': {
|
81 |
+
'dict': texttospeech_func,
|
82 |
+
'func': texttospeech
|
83 |
+
}
|
84 |
+
```
|
85 |
+
|
86 |
+
5. **Update the Chatbot Layout**
|
87 |
+
- Go to the Blocks Chatbot layout and add a new checkbox for your plugin as:
|
88 |
+
```python
|
89 |
+
texttospeech = gr.Checkbox(label="📝🗣️Text-To-Speech", value=False)
|
90 |
+
```
|
91 |
+
- Add the new checkbox component to your submit and click events for your chatbot and to the predict function accordingly.
|
92 |
+
- And also to the `plugins` list in `predict`
|
93 |
+
```python
|
94 |
+
plugins = [music_gen, stable_diff, image_cap, top_news, texttospeech]
|
95 |
+
```
|
96 |
+
|
97 |
+
Thats it! you are have added your own brand new CHATGPT Plugin for yourself. Go PLAY!!
|
98 |
+
"""
|
99 |
|
100 |
# managing conversation with Plugins
|
101 |
def run_conversation(user_input, function_call_decision):
|