Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit36decad

Browse files
committed
merge
2 parents56958a0 +e73460b commit36decad

File tree

4 files changed

+137
-64
lines changed

4 files changed

+137
-64
lines changed

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111

1212
##0.0.27
1313

14+
###New Features
15+
16+
- Increase screen capture resolution ([#30](https://github.com/AnswerDotAI/dialoghelper/pull/30)), thanks to[@austinvhuang](https://github.com/austinvhuang)
17+
18+
##0.0.25
19+
20+
###New Features
21+
22+
- Unify return signals to use the blocking endpoint for getting signals/return values ([#29](https://github.com/AnswerDotAI/dialoghelper/pull/29)), thanks to[@austinvhuang](https://github.com/austinvhuang)
23+
24+
##0.0.24
25+
1426
###Bugs Squashed
1527

1628
- remove isCapturing restriction in capture_screen ([#26](https://github.com/AnswerDotAI/dialoghelper/pull/26)), thanks to[@austinvhuang](https://github.com/austinvhuang)

‎dialoghelper/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
<<<<<<<HEAD
12
__version__="0.0.29"
3+
=======
4+
__version__="0.0.29"
5+
>>>>>>>austinvhuang/highres-ocr
26
from .coreimport*

‎dialoghelper/experimental.py‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
__all__= ['iife','load_screenshot_js','start_screen_share','stop_screen_share','capture_screen']
77

88
# %% ../nbs/01_experimental.ipynb
9+
importuuid,json
910
fromimportlibimportresources
10-
importuuid
11-
fromfasthtml.commonimportDiv,Script
12-
importjson
11+
fromfasthtml.commonimportDiv,Script
1312
fromclaudetteimportToolResult
1413
from .coreimport*
1514
fromhttpximportpostasxpost
1615

1716
# %% ../nbs/01_experimental.ipynb
18-
def_pop_data(data_id,timeout=20,condition=None,fail_msg="`_pop_data` failed to return a value."):
19-
result=xpost('http://localhost:5001/pop_data_blocking_',data={'data_id':data_id},timeout=timeout)
20-
ifresult.status_code==200andresult.text.strip():
21-
try:
22-
if (data:=result.json())and (notconditionorcondition(data)):returndata
23-
exceptjson.JSONDecodeErrorase:print(f"JSON decode error:{e}")
24-
raiseRuntimeError(fail_msg)
17+
def_pop_data(data_id,timeout=20):
18+
params= {'data_id':data_id,'timeout':timeout}
19+
result=xpost('http://localhost:5001/pop_data_blocking_',data=params,timeout=timeout+1)
20+
ifresult.status_code==200andresult.text.strip():
21+
if (data:=result.json()):returndata
22+
# except json.JSONDecodeError as e: print(f"JSON decode error: {e}")
23+
raiseRuntimeError("No data received")
24+
raiseRuntimeError(result.status_code)
2525

2626
# %% ../nbs/01_experimental.ipynb
2727
defiife(code:str)->str:
@@ -40,13 +40,14 @@ def load_screenshot_js(force=False, timeout=5):
4040
"Load screenshot capability and wait for confirmation it's ready."
4141
global_js_loaded
4242
if_js_loadedandnotforce:return
43-
print("Loading screenshot.js ...")
43+
# print("Loading screenshot.js ...")
4444
status_id=str(uuid.uuid4())
45-
js_content= (resources.files('dialoghelper')/'screenshot.js').read_text()
45+
js_content= (resources.files('dialoghelper')/'screenshot.js').read_text()
4646
iife(js_content+f'sendDataToServer("{status_id}", {{"js_status": "ready"}});')
47-
data=_pop_data(status_id,timeout,condition=lambdad:d.get('js_status')=='ready',fail_msg="Failed to load screenshot.js.")
47+
data=_pop_data(status_id,timeout)
48+
if (stat:=data.get('js_status'))!='ready':raiseRuntimeError(f"Failed to load screenshot.js:{stat}")
4849
_js_loaded=True
49-
print("Screenshot.js loaded and ready")
50+
# print("Screenshot.js loaded and ready")
5051

5152
# %% ../nbs/01_experimental.ipynb
5253
_screen_share_active=False
@@ -57,37 +58,39 @@ def start_screen_share(timeout=45):
5758
load_screenshot_js()
5859
status_id=str(uuid.uuid4())
5960
iife(f'startPersistentScreenShare("{status_id}");')
60-
print("Requesting screen share permission ...")
61-
data=_pop_data(status_id,timeout,condition=lambdad:d.get('js_status')=='ready',fail_msg="Screen share failed.")
61+
# print("Requesting screen share permission ...")
62+
data=_pop_data(status_id,timeout)
6263
js_status=data.get('js_status')
63-
ifjs_status=='ready':
64+
ifjs_status=='ready':
6465
_screen_share_active=True
65-
print("Screen share started successfully.")
66-
elifjs_status=='error':raiseRuntimeError(f"Screen share failed:{data.get('error','Unknown error')}")
67-
elifjs_status=='connecting':raiseRuntimeError("Screen share timed out after {timeout} seconds.")
66+
# print("Screen share started successfully.")
67+
elifjs_status=='error':raiseRuntimeError(f"Screen share failed:{data.get('error','Unknown error')}")
68+
elifjs_status=='connecting':raiseRuntimeError("Screen share timed out after {timeout} seconds.")
6869

6970
# %% ../nbs/01_experimental.ipynb
7071
defstop_screen_share():
71-
"Stop persistent screen sharing session."
72-
global_screen_share_active
73-
load_screenshot_js()
74-
iife('stopPersistentScreenShare();')
75-
_screen_share_active=False
76-
print("Screen share stopped.")
72+
"Stop persistent screen sharing session."
73+
global_screen_share_active
74+
load_screenshot_js()
75+
iife('stopPersistentScreenShare();')
76+
_screen_share_active=False
77+
# print("Screen share stopped.")
7778

7879
# %% ../nbs/01_experimental.ipynb
7980
defcapture_screen():
8081
"Capture screenshot, automatically starting screen share if needed."
8182
global_screen_share_active
8283
load_screenshot_js()
8384
ifnot_screen_share_active:
84-
print("🔄 No active screen share, starting one...")
85+
# print("🔄 No active screen share, starting one...")
8586
result=start_screen_share()
8687
ifnot_screen_share_active:raiseRuntimeError(f"Failed to start screen share:{result}")
8788
data_id=str(uuid.uuid4())
8889
screenshot_code=f'captureScreenFromStream("{data_id}");'
89-
print("📸 Capturing from persistent stream...")
90+
# print("📸 Capturing from persistent stream...")
9091
iife(screenshot_code)
91-
data=_pop_data(data_id,timeout=5,condition=lambdad:'img_data'indand'img_type'ind,fail_msg="Screenshot capture failed, failed to retrieve data.")
92+
data=_pop_data(data_id,timeout=45)
9293
if'error'indata:raiseRuntimeError(f"Screenshot failed:{data['error']}")
94+
ifnot ('img_data'indataand'img_type'indata):
95+
raiseRuntimeError("Screenshot capture failed, failed to retrieve data.")
9396
returnToolResult(data=data['img_data'],result_type=data['img_type'])

‎nbs/01_experimental.ipynb‎

Lines changed: 89 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
"outputs": [],
2929
"source": [
3030
"#| export\n",
31-
"\n",
31+
"import uuid,json\n",
3232
"from importlib import resources\n",
33-
"import uuid\n",
34-
"from fasthtml.common import Div, Script\n",
35-
"import json\n",
33+
"from fasthtml.common import Div,Script\n",
3634
"from claudette import ToolResult\n",
3735
"from dialoghelper.core import *\n",
3836
"from httpx import post as xpost"
@@ -46,13 +44,14 @@
4644
"outputs": [],
4745
"source": [
4846
"#| export\n",
49-
"def _pop_data(data_id, timeout=20, condition=None, fail_msg =\"`_pop_data` failed to return a value.\"):\n",
50-
" result = xpost('http://localhost:5001/pop_data_blocking_', data={'data_id': data_id}, timeout=timeout)\n",
51-
" if result.status_code == 200 and result.text.strip():\n",
52-
" try:\n",
53-
" if (data := result.json()) and (not condition or condition(data)): return data\n",
54-
" except json.JSONDecodeError as e: print(f\"JSON decode error: {e}\")\n",
55-
" raise RuntimeError(fail_msg)"
47+
"def _pop_data(data_id, timeout=20):\n",
48+
" params = {'data_id': data_id, 'timeout':timeout}\n",
49+
" result = xpost('http://localhost:5001/pop_data_blocking_', data=params, timeout=timeout+1)\n",
50+
" if result.status_code==200 and result.text.strip():\n",
51+
" if (data := result.json()): return data\n",
52+
"# except json.JSONDecodeError as e: print(f\"JSON decode error: {e}\")\n",
53+
" raise RuntimeError(\"No data received\")\n",
54+
" raise RuntimeError(result.status_code)"
5655
]
5756
},
5857
{
@@ -63,7 +62,6 @@
6362
"outputs": [],
6463
"source": [
6564
"#| export\n",
66-
"\n",
6765
"def iife(code: str) -> str:\n",
6866
"\"Wrap javascript code string in an IIFE and execute it via `add_html`\"\n",
6967
" trigger_script = f'''\n",
@@ -82,20 +80,39 @@
8280
"outputs": [],
8381
"source": [
8482
"#| export\n",
85-
"\n",
8683
"_js_loaded = False\n",
8784
"\n",
8885
"def load_screenshot_js(force=False, timeout=5):\n",
8986
"\"Load screenshot capability and wait for confirmation it's ready.\"\n",
9087
" global _js_loaded\n",
9188
" if _js_loaded and not force: return\n",
92-
" print(\"Loading screenshot.js ...\")\n",
89+
"# print(\"Loading screenshot.js ...\")\n",
9390
" status_id = str(uuid.uuid4())\n",
94-
" js_content = (resources.files('dialoghelper') /'screenshot.js').read_text()\n",
91+
" js_content = (resources.files('dialoghelper')/'screenshot.js').read_text()\n",
9592
" iife(js_content + f'sendDataToServer(\"{status_id}\", {{\"js_status\":\"ready\"}});')\n",
96-
" data = _pop_data(status_id, timeout, condition=lambda d: d.get('js_status') == 'ready', fail_msg=\"Failed to load screenshot.js.\")\n",
93+
" data = _pop_data(status_id, timeout)\n",
94+
" if (stat:=data.get('js_status'))!='ready': raise RuntimeError(f\"Failed to load screenshot.js: {stat}\")\n",
9795
" _js_loaded = True\n",
98-
" print(\"Screenshot.js loaded and ready\")"
96+
"# print(\"Screenshot.js loaded and ready\")"
97+
]
98+
},
99+
{
100+
"cell_type":"code",
101+
"execution_count":null,
102+
"id":"a6ad43ee",
103+
"metadata": {},
104+
"outputs": [
105+
{
106+
"name":"stdout",
107+
"output_type":"stream",
108+
"text": [
109+
"Loading screenshot.js ...\n",
110+
"Screenshot.js loaded and ready\n"
111+
]
112+
}
113+
],
114+
"source": [
115+
"# load_screenshot_js()"
99116
]
100117
},
101118
{
@@ -106,7 +123,6 @@
106123
"outputs": [],
107124
"source": [
108125
"#| export\n",
109-
"\n",
110126
"_screen_share_active = False\n",
111127
"\n",
112128
"def start_screen_share(timeout=45):\n",
@@ -115,14 +131,24 @@
115131
" load_screenshot_js()\n",
116132
" status_id = str(uuid.uuid4())\n",
117133
" iife(f'startPersistentScreenShare(\"{status_id}\");')\n",
118-
" print(\"Requesting screen share permission ...\")\n",
119-
" data = _pop_data(status_id, timeout, condition=lambda d: d.get('js_status') == 'ready', fail_msg=\"Screen share failed.\")\n",
134+
"# print(\"Requesting screen share permission ...\")\n",
135+
" data = _pop_data(status_id, timeout)\n",
120136
" js_status = data.get('js_status')\n",
121-
" if js_status =='ready':\n",
137+
" if js_status=='ready':\n",
122138
" _screen_share_active = True\n",
123-
" print(\"Screen share started successfully.\")\n",
124-
" elif js_status == 'error': raise RuntimeError(f\"Screen share failed: {data.get('error', 'Unknown error')}\")\n",
125-
" elif js_status == 'connecting': raise RuntimeError(\"Screen share timed out after {timeout} seconds.\")"
139+
"# print(\"Screen share started successfully.\")\n",
140+
" elif js_status=='error': raise RuntimeError(f\"Screen share failed: {data.get('error', 'Unknown error')}\")\n",
141+
" elif js_status=='connecting': raise RuntimeError(\"Screen share timed out after {timeout} seconds.\")"
142+
]
143+
},
144+
{
145+
"cell_type":"code",
146+
"execution_count":null,
147+
"id":"0bed97c1",
148+
"metadata": {},
149+
"outputs": [],
150+
"source": [
151+
"# start_screen_share()"
126152
]
127153
},
128154
{
@@ -133,14 +159,13 @@
133159
"outputs": [],
134160
"source": [
135161
"#| export\n",
136-
"\n",
137162
"def stop_screen_share():\n",
138-
"\"Stop persistent screen sharing session.\"\n",
139-
" global _screen_share_active\n",
140-
" load_screenshot_js()\n",
141-
" iife('stopPersistentScreenShare();')\n",
142-
" _screen_share_active = False\n",
143-
" print(\"Screen share stopped.\")"
163+
"\"Stop persistent screen sharing session.\"\n",
164+
"global _screen_share_active\n",
165+
"load_screenshot_js()\n",
166+
"iife('stopPersistentScreenShare();')\n",
167+
"_screen_share_active = False\n",
168+
"# print(\"Screen share stopped.\")"
144169
]
145170
},
146171
{
@@ -151,23 +176,52 @@
151176
"outputs": [],
152177
"source": [
153178
"#| export\n",
154-
"\n",
155179
"def capture_screen():\n",
156180
"\"Capture screenshot, automatically starting screen share if needed.\"\n",
157181
" global _screen_share_active\n",
158182
" load_screenshot_js()\n",
159183
" if not _screen_share_active:\n",
160-
" print(\"🔄 No active screen share, starting one...\")\n",
184+
"# print(\"🔄 No active screen share, starting one...\")\n",
161185
" result = start_screen_share()\n",
162186
" if not _screen_share_active: raise RuntimeError(f\"Failed to start screen share: {result}\")\n",
163187
" data_id = str(uuid.uuid4())\n",
164188
" screenshot_code = f'captureScreenFromStream(\"{data_id}\");'\n",
165-
" print(\"📸 Capturing from persistent stream...\")\n",
189+
"# print(\"📸 Capturing from persistent stream...\")\n",
166190
" iife(screenshot_code)\n",
167-
" data = _pop_data(data_id, timeout=5, condition=lambda d: 'img_data' in d and 'img_type' in d, fail_msg=\"Screenshot capture failed, failed to retrieve data.\")\n",
191+
" data = _pop_data(data_id, timeout=45)\n",
168192
" if 'error' in data: raise RuntimeError(f\"Screenshot failed: {data['error']}\")\n",
193+
" if not ('img_data' in data and 'img_type' in data):\n",
194+
" raise RuntimeError(\"Screenshot capture failed, failed to retrieve data.\")\n",
169195
" return ToolResult(data=data['img_data'], result_type=data['img_type'])"
170196
]
197+
},
198+
{
199+
"cell_type":"markdown",
200+
"id":"f17beb15",
201+
"metadata": {},
202+
"source": [
203+
"## export -"
204+
]
205+
},
206+
{
207+
"cell_type":"code",
208+
"execution_count":null,
209+
"id":"36548c80",
210+
"metadata": {},
211+
"outputs": [],
212+
"source": [
213+
"#|hide\n",
214+
"from nbdev import nbdev_export\n",
215+
"nbdev_export()"
216+
]
217+
},
218+
{
219+
"cell_type":"code",
220+
"execution_count":null,
221+
"id":"778f4ad6",
222+
"metadata": {},
223+
"outputs": [],
224+
"source": []
171225
}
172226
],
173227
"metadata": {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp