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