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