File size: 1,443 Bytes
b560569
 
751e28f
0f9e24f
b560569
751e28f
 
b560569
0f9e24f
751e28f
b560569
751e28f
b560569
 
 
0f9e24f
 
 
734a45c
 
0f9e24f
 
734a45c
b560569
751e28f
0f9e24f
734a45c
751e28f
 
b560569
751e28f
 
0f9e24f
734a45c
 
0f9e24f
e3447a5
523260c
7ab0240
734a45c
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
31
32
33
34
35
36
37
38
39
40
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])

    demo.load(fn=show_token, inputs=[], outputs=token_display, every=1)

demo.launch(server_name="0.0.0.0", server_port=7860)