Space

UI Spaces Echo

ui-spaces/ui-spaces-echo

Show env and storage check

ui-spaces committed on October 21, 2026

eadeec2af284cd3d3978811e79da01e0c0ad9fa0Parent 3cb729eBrowse files

1 file changed+25 -1

app.py

Modified+25 -1
Lines 1 to 3 become lines 1 to 5
@@ -1,3 +1,5 @@
1Added: import os
2Added:
13import gradio as gr
24import humanize
35
Lines 7 to 13 become lines 9 to 37
@@ -7,7 +9,29 @@
79 return f"{text} ({n} characters, {humanize.apnumber(n)})"
810
911
10Removed: demo = gr.Interface(fn=echo, inputs=gr.Textbox(label="Text"), outputs=gr.Textbox(label="Echo"), title="UI Spaces Echo")
12Added: def env_check():
13Added: greeting = os.environ.get("UI_GREETING", "<unset>")
14Added: token_set = "set" if os.environ.get("UI_TOKEN") else "unset"
15Added: data_ok = os.path.isdir("/data") and os.access("/data", os.W_OK)
16Added: if data_ok:
17Added: path = "/data/ui-spaces-counter.txt"
18Added: count = int(open(path).read()) + 1 if os.path.exists(path) else 1
19Added: with open(path, "w") as f:
20Added: f.write(str(count))
21Added: else:
22Added: count = "no /data"
23Added: return f"UI_GREETING={greeting}; UI_TOKEN is {token_set}; /data writable={data_ok}; boots={count}"
24Added:
25Added:
26Added: BOOT = env_check()
27Added: print("ui-spaces env check:", BOOT, flush=True)
28Added:
29Added: with gr.Blocks(title="UI Spaces Echo") as demo:
30Added: gr.Markdown("# UI Spaces Echo")
31Added: gr.Markdown(BOOT)
32Added: inp = gr.Textbox(label="Text")
33Added: out = gr.Textbox(label="Echo")
34Added: gr.Button("Submit").click(echo, inp, out, api_name="predict")
1135
1236if __name__ == "__main__":
1337 demo.launch()