File size: 1,440 Bytes
b560569
 
751e28f
a0b418d
b560569
751e28f
a0b418d
b560569
0f9e24f
a0b418d
751e28f
b560569
751e28f
b560569
 
 
0f9e24f
 
 
734a45c
 
0f9e24f
 
734a45c
b560569
0f9e24f
d45a226
751e28f
b560569
751e28f
0f9e24f
94fc4da
734a45c
 
0f9e24f
e3447a5
d45a226
 
 
7ab0240
d45a226
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
41
42
import gradio as gr

# shared state
token_received = {"status": False, "token": "", "client_id": ""}

# 1) this will be called by POST
def receive_token(accessToken: str, client_id: str):
    token_received["status"] = True
    token_received["token"] = accessToken
    token_received["client_id"] = client_id
    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:
    hidden_token = gr.Textbox(visible=False)
    hidden_btn = gr.Button(visible=False)
    hidden_btn.click(fn=receive_token, inputs=hidden_token, outputs=[])

    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])

    # βœ… Correct usage of Timer
    timer = gr.Timer(1.0)
    timer.tick(fn=show_token, outputs=token_display)

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