From 3bf8a5def5039c35c5d8c4c85547da80bf44b997 Mon Sep 17 00:00:00 2001 From: Dan Li <972648237@qq.com> Date: Sat, 22 Mar 2025 07:17:31 +0300 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8D=95=E5=A4=84=E7=90=86mac?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=B1=8F=E5=B9=95=E4=BC=9A=E7=88=86=E7=82=B8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradio_ui/app.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gradio_ui/app.py b/gradio_ui/app.py index 94df407..528d7e9 100644 --- a/gradio_ui/app.py +++ b/gradio_ui/app.py @@ -13,6 +13,7 @@ from gradio_ui.loop import ( ) import base64 from xbrain.utils.config import Config +import platform from util.download_weights import OMNI_PARSER_DIR CONFIG_DIR = Path("~/.anthropic").expanduser() @@ -210,6 +211,11 @@ def get_header_image_base64(): except Exception as e: print(f"Failed to load header image: {e}") return None + +def _get_region(queue): + from util.screen_selector import ScreenSelector + region = ScreenSelector().get_selection() + queue.put(region) def run(): @@ -277,8 +283,27 @@ def run(): state["screen_region"] = region return f"Selected region: {region}" return "Selection cancelled" - - select_region_btn.click(fn=select_screen_region, inputs=[state], outputs=[gr.Textbox(label="Region Info")]) + + def select_screen_region_mac(state): + import multiprocessing as mp + ctx = mp.get_context('spawn') + queue = ctx.Queue() + + p = ctx.Process(target=_get_region, args=(queue,)) + p.start() + p.join() + + region = queue.get() if not queue.empty() else None + + if region: + state["screen_region"] = region + return f"Selected region: {region}" + return "Selection cancelled" + + if platform.system() == 'Darwin': + select_region_btn.click(fn=select_screen_region_mac, inputs=[state], outputs=[gr.Textbox(label="Region Info")]) + else: + select_region_btn.click(fn=select_screen_region_mac, inputs=[state], outputs=[gr.Textbox(label="Region Info")]) with gr.Row(): with gr.Column(scale=8): chat_input = gr.Textbox(show_label=False, placeholder="Type a message to send to Omniparser + X ...", container=False)