gradio: Unable to update gr.Examples getting AttributeError: 'Examples' object has no attribute '_id'
Describe the bug
while looking deeply for the answers myself I am frustrated and could not find the solution
so Below is some code
# Function for generating some examples
def generate_examples():
extracted_list = ['completion1','completion2','completion3','completion4']
return gr.Examples.update(examples=extracted_list)
# Gradio Interface
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=0.7):
chatbot = gr.Chatbot(
value=[[None,"Hey, can I help you get something?"],],
height=500,
label="Stickse Sales Assistant",
)
with gr.Row():
with gr.Column(scale=0.85):
txt = gr.Textbox(
show_label=False,
container=False,
placeholder="Enter text and press enter",
)
_examples = gr.Examples(
examples=['mice','ants','snails', 'bees', 'moth'],
inputs=txt,
label="Suggestions"
)
with gr.Column(scale=0.15, min_width=0):
btn = gr.Button("Send")
with gr.Column(scale=0.3):
radio = gr.Dropdown(
container=False,
choices=['gpt-3.5-turbo','gpt-3.5-turbo-16k','gpt-3.5-turbo-0613','gpt-3.5-turbo-16k-0613'],
label="Model",
value='gpt-3.5-turbo-16k',
)
model_details = gr.Markdown(
container=True,
value=MODELS[radio.value], label="Model Details",)
clear = gr.Button("Clear Conversation")
# this is where the issue is
s = gr.Button("UPDATE EXAMPLES")
radio.change(change_model_details, [radio], [model_details])
clear.click(init_history, inputs =[],outputs = chatbot,)
btn.click(add_text, [chatbot, txt], [chatbot, txt], queue=True).then(
generate_response, inputs =[chatbot,radio],outputs = [chatbot])
txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=True).then(
generate_response, inputs =[chatbot,radio],outputs = [chatbot])
# this is where I am calling the button click
s.click(generate_examples,inputs=[],outputs = [_examples])
demo.queue()
demo.launch()
This is the issue I get on my terminal
> python main.py
Traceback (most recent call last):
File "D:\projects\SalesRep\main.py", line 272, in <module>
s.click(fn=generate_examples,inputs=[],outputs = [_examples])
File "D:\projects\SalesRep\env\Lib\site-packages\gradio\events.py", line 139, in __call__
dep, dep_index = self.trigger.set_event_trigger(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\SalesRep\env\Lib\site-packages\gradio\blocks.py", line 285, in set_event_trigger
"outputs": [block._id for block in outputs],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\SalesRep\env\Lib\site-packages\gradio\blocks.py", line 285, in <listcomp>
"outputs": [block._id for block in outputs],
^^^^^^^^^
AttributeError: 'Examples' object has no attribute '_id'
so The gr.Examples component is what I want to update and I am unable to do it.
There was a similar issue #3817 but was closed and the discussion form linked does not exist
https://github.com/gradio-app/gradio/discussions/3169
when I comment the line s.click(generate_examples,inputs=[],outputs = [_examples])
The gradio app launches else it doesnt even lauch now
Have you searched existing issues? 🔎
- I have searched and found no existing issues
Reproduction
import gradio as gr
def generate_examples():
extracted_list = ['completion1','completion2','completion3','completion4']
return gr.Examples.update(examples=extracted_list)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=0.7):
chatbot = gr.Chatbot(
value=[[None,"Hey, can I help you get something?"],],
height=500,
label="Stickse Sales Assistant",
)
with gr.Row():
with gr.Column(scale=0.85):
txt = gr.Textbox(
show_label=False,
container=False,
placeholder="Enter text and press enter",
)
_examples = gr.Examples(
examples=['mice','ants','snails', 'bees', 'moth'],
inputs=txt,
label="Suggestions"
)
with gr.Column(scale=0.15, min_width=0):
btn = gr.Button("Send")
with gr.Column(scale=0.3):
radio = gr.Dropdown(
container=False,
choices=['gpt-3.5-turbo','gpt-3.5-turbo-16k','gpt-3.5-turbo-0613','gpt-3.5-turbo-16k-0613'],
label="Model",
value='gpt-3.5-turbo-16k',
)
# this is where the issue is
s = gr.Button("UPDATE EXAMPLES")
# this is where I am calling the button click
# s.click(generate_examples,inputs=[],outputs = [_examples])
demo.queue()
demo.launch()
Logs
Traceback (most recent call last):
File "D:\projects\SalesRep\main.py", line 272, in <module>
s.click(fn=generate_examples,inputs=[],outputs = [_examples])
File "D:\projects\SalesRep\env\Lib\site-packages\gradio\events.py", line 139, in __call__
dep, dep_index = self.trigger.set_event_trigger(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\SalesRep\env\Lib\site-packages\gradio\blocks.py", line 285, in set_event_trigger
"outputs": [block._id for block in outputs],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\SalesRep\env\Lib\site-packages\gradio\blocks.py", line 285, in <listcomp>
"outputs": [block._id for block in outputs],
^^^^^^^^^
AttributeError: 'Examples' object has no attribute '_id'
System Info
Gradio Environment Information:
Operating System: Windows
gradio version: 3.39.0
gradio Dependencies:
aiofiles: 23.1.0
aiohttp: 3.8.5
altair: 5.0.1
fastapi: 0.99.1
ffmpy: 0.3.1
gradio-client: 0.3.0
httpx: 0.24.1
huggingface-hub: 0.16.4
jinja2: 3.1.2
markdown-it-py: 2.2.0
markupsafe: 2.1.3
matplotlib: 3.7.2
mdit-py-plugins: 0.3.3
numpy: 1.25.1
orjson: 3.9.2
packaging: 23.1
pandas: 2.0.3
pillow: 10.0.0
pydantic: 1.10.12
pydub: 0.25.1
python-multipart: 0.0.6
pyyaml: 6.0.1
requests: 2.31.0
semantic-version: 2.10.0
typing-extensions: 4.7.1
uvicorn: 0.23.1
websockets: 11.0.3
gradio_client version: 0.3.0
gradio_client Dependencies:
fsspec: 2023.6.0
httpx: 0.24.1
huggingface-hub: 0.16.4
packaging: 23.1
requests: 2.31.0
typing-extensions: 4.7.1
websockets: 11.0.3
Severity
Blocking usage of gradio
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 21 (4 by maintainers)
For now, can you have multiple predefined gr.Examples objects, and hide the visibility based on the interaction?