Spaces:
Running
Running
import gradio as gr | |
# shared state | |
token_received = {"status": False, "token": ""} | |
# 1) this will be called by POST | |
def receive_token(accessToken: str): | |
token_received["status"] = True | |
token_received["token"] = accessToken | |
return {"status": "ok"} | |
# 2) this just drives your UI | |
def check_status(): | |
return "✅ Code received" if token_received["status"] else "❌ Code not received" | |
def show_token(): | |
return token_received["token"] if token_received["status"] else "" | |
def reset_status(): | |
token_received["status"] = False | |
token_received["token"] = "" | |
return "❌ Code not received", "" | |
with gr.Blocks() as demo: | |
# we don’t actually show these widgets in the UI: | |
hidden_token = gr.Textbox(visible=False) | |
hidden_btn = gr.Button(visible=False) | |
# wire up the hidden POST→function | |
hidden_btn.click(fn=receive_token, inputs=hidden_token, outputs=[]) | |
# your visible UI | |
status_box = gr.Textbox(value=check_status(), label="Token Status", interactive=False) | |
token_display = gr.Textbox(value=show_token(), label="Received Token", interactive=False) | |
with gr.Row(): | |
refresh = gr.Button("Refresh").click(fn=check_status, outputs=status_box) | |
reset = gr.Button("Reset Status").click(fn=reset_status, outputs=[status_box, token_display]) | |
gr.load(fn=show_token, inputs=[], outputs=token_display, every=1) | |
demo.launch(server_name="0.0.0.0", server_port=7860) |