File size: 1,073 Bytes
7f055a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# demo/app.py
import gradio as gr
from gradio_keylock import KeylockDecoderComponent, AppServerLogic
# Instantiate the backend logic once
server_logic = AppServerLogic()
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# Gradio KeyLock Component Demo")
gr.Markdown(
"Upload an image created by the component to see the decoded payload. "
"You can also generate a new image below."
)
# Instantiate the custom component, passing the server logic
keylock_component = KeylockDecoderComponent(server_logic=server_logic)
# Create a separate component to display the output
output_json = gr.JSON(label="Decoded Payload")
# Define a function to update the output when the component's value changes
def get_payload(result):
if result and result.get("status") == "Success":
return result.get("payload")
return None
# Link the component's "change" event to the output display
keylock_component.change(fn=get_payload, inputs=keylock_component, outputs=output_json)
demo.launch() |