Skip to content

Instantly share code, notes, and snippets.

@knowsuchagency
Last active August 6, 2024 04:08
Show Gist options
  • Save knowsuchagency/f10969d6cf962f40d8032beb666e2fe0 to your computer and use it in GitHub Desktop.
Save knowsuchagency/f10969d6cf962f40d8032beb666e2fe0 to your computer and use it in GitHub Desktop.
gradio render example
import gradio as gr
with gr.Blocks() as demo:
subscribed = gr.State(False)
update_subscription_btn = gr.Button("Update Subscription")
@update_subscription_btn.click(inputs=subscribed, outputs=subscribed)
def update_subscription(subscribed):
return not subscribed
@gr.render(inputs=subscribed)
def render_subscription(subscribed):
if subscribed:
gr.Textbox("You are subscribed")
gr.Textbox("You will be billed $10.00 every month")
else:
gr.Textbox("You are not subscribed")
demo.launch()
import gradio as gr
with gr.Blocks() as demo:
subscribed = gr.State(False)
@gr.render(inputs=subscribed)
def render_subscription(subscribed):
update_subscription_btn = gr.Button("Update Subscription")
@update_subscription_btn.click(inputs=subscribed, outputs=subscribed)
def update_subscription(subscribed):
return not subscribed
if subscribed:
gr.Textbox("You are subscribed")
gr.Textbox("You will be billed $10.00 every month")
else:
gr.Textbox("You are not subscribed")
demo.launch()
"""
File ".../.venv/lib/python3.12/site-packages/gradio/blocks.py", line 575, in get_config
"inputs": [block._id for block in self.inputs],
^^^^^^^^^
AttributeError: 'bool' object has no attribute '_id'
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment