Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
# shared state
|
4 |
-
token_received = {"status": False}
|
5 |
|
6 |
# 1) this will be called by POST
|
7 |
def receive_token(accessToken: str):
|
8 |
token_received["status"] = True
|
|
|
9 |
return {"status": "ok"}
|
10 |
|
11 |
# 2) this just drives your UI
|
12 |
def check_status():
|
13 |
return "✅ Code received" if token_received["status"] else "❌ Code not received"
|
14 |
|
|
|
|
|
|
|
15 |
def reset_status():
|
16 |
token_received["status"] = False
|
17 |
-
|
|
|
18 |
|
19 |
with gr.Blocks() as demo:
|
20 |
# we don’t actually show these widgets in the UI:
|
21 |
-
hidden_token = gr.Textbox()
|
22 |
hidden_btn = gr.Button(visible=False)
|
23 |
# wire up the hidden POST→function
|
24 |
hidden_btn.click(fn=receive_token, inputs=hidden_token, outputs=[])
|
25 |
|
26 |
# your visible UI
|
27 |
status_box = gr.Textbox(value=check_status(), label="Token Status", interactive=False)
|
|
|
28 |
with gr.Row():
|
29 |
refresh = gr.Button("Refresh").click(fn=check_status, outputs=status_box)
|
30 |
-
reset = gr.Button("Reset Status").click(fn=reset_status, outputs=status_box)
|
31 |
-
|
32 |
-
|
33 |
|
34 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
# shared state
|
4 |
+
token_received = {"status": False, "token": ""}
|
5 |
|
6 |
# 1) this will be called by POST
|
7 |
def receive_token(accessToken: str):
|
8 |
token_received["status"] = True
|
9 |
+
token_received["token"] = accessToken
|
10 |
return {"status": "ok"}
|
11 |
|
12 |
# 2) this just drives your UI
|
13 |
def check_status():
|
14 |
return "✅ Code received" if token_received["status"] else "❌ Code not received"
|
15 |
|
16 |
+
def show_token():
|
17 |
+
return token_received["token"] if token_received["status"] else ""
|
18 |
+
|
19 |
def reset_status():
|
20 |
token_received["status"] = False
|
21 |
+
token_received["token"] = ""
|
22 |
+
return "❌ Code not received", ""
|
23 |
|
24 |
with gr.Blocks() as demo:
|
25 |
# we don’t actually show these widgets in the UI:
|
26 |
+
hidden_token = gr.Textbox(visible=False)
|
27 |
hidden_btn = gr.Button(visible=False)
|
28 |
# wire up the hidden POST→function
|
29 |
hidden_btn.click(fn=receive_token, inputs=hidden_token, outputs=[])
|
30 |
|
31 |
# your visible UI
|
32 |
status_box = gr.Textbox(value=check_status(), label="Token Status", interactive=False)
|
33 |
+
token_display = gr.Textbox(value=show_token(), label="Received Token", interactive=False)
|
34 |
with gr.Row():
|
35 |
refresh = gr.Button("Refresh").click(fn=check_status, outputs=status_box)
|
36 |
+
reset = gr.Button("Reset Status").click(fn=reset_status, outputs=[status_box, token_display])
|
37 |
+
demo.load(fn=show_token, outputs=token_display, every=1) # Optionally update token display on load
|
|
|
38 |
|
39 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|