Update app.py
Browse files
app.py
CHANGED
|
@@ -81,28 +81,28 @@ with gr.Blocks(title="去背服務測試") as app:
|
|
| 81 |
gr.Markdown("## ✂️ 去背服務測試")
|
| 82 |
|
| 83 |
with gr.Tabs():
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
btn = gr.Button("Remove Background", variant="primary")
|
| 90 |
btn.click(process, inputs=img_in, outputs=img_out)
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
|
| 107 |
# --- 4. 啟動 ---
|
| 108 |
if __name__ == "__main__":
|
|
|
|
| 81 |
gr.Markdown("## ✂️ 去背服務測試")
|
| 82 |
|
| 83 |
with gr.Tabs():
|
| 84 |
+
# Tab 1: Image Processing
|
| 85 |
+
with gr.Tab("✂️ Remove Background"):
|
| 86 |
+
with gr.Row():
|
| 87 |
+
img_in = gr.Image(type="pil", label="Input Image")
|
| 88 |
+
img_out = gr.Image(type="pil", label="Result (PNG)", format="png")
|
| 89 |
btn = gr.Button("Remove Background", variant="primary")
|
| 90 |
btn.click(process, inputs=img_in, outputs=img_out)
|
| 91 |
|
| 92 |
+
# Tab 2: System Monitor (UI for Space Page)
|
| 93 |
+
with gr.Tab("📊 System Monitor"):
|
| 94 |
+
gr.Markdown("Click the button below to check current server load.")
|
| 95 |
+
stats_output = gr.Markdown("### Status: Waiting...")
|
| 96 |
+
refresh_btn = gr.Button("🔄 Refresh Stats")
|
| 97 |
+
refresh_btn.click(get_system_stats_ui, outputs=stats_output)
|
| 98 |
+
# Auto-load stats when page opens
|
| 99 |
+
demo.load(get_system_stats_ui, outputs=stats_output)
|
| 100 |
|
| 101 |
+
# Hidden API Route for React Frontend
|
| 102 |
+
# The frontend calls this via client.predict("/status")
|
| 103 |
+
api_status = gr.JSON(visible=False, label="API Response")
|
| 104 |
+
api_btn = gr.Button("API Status", visible=False)
|
| 105 |
+
api_btn.click(get_system_stats_api, outputs=api_status, api_name="status")
|
| 106 |
|
| 107 |
# --- 4. 啟動 ---
|
| 108 |
if __name__ == "__main__":
|