langfun 0.1.2.dev202503220803__py3-none-any.whl → 0.1.2.dev202503240804__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langfun/core/eval/v2/progress_tracking.py +2 -1
- langfun/core/modalities/mime.py +21 -0
- langfun/core/modalities/mime_test.py +16 -0
- {langfun-0.1.2.dev202503220803.dist-info → langfun-0.1.2.dev202503240804.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202503220803.dist-info → langfun-0.1.2.dev202503240804.dist-info}/RECORD +8 -8
- {langfun-0.1.2.dev202503220803.dist-info → langfun-0.1.2.dev202503240804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202503220803.dist-info → langfun-0.1.2.dev202503240804.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202503220803.dist-info → langfun-0.1.2.dev202503240804.dist-info}/top_level.txt +0 -0
@@ -13,6 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
"""Tracking evaluation run progress."""
|
15
15
|
|
16
|
+
import os
|
16
17
|
import langfun.core as lf
|
17
18
|
from langfun.core.eval.v2 import example as example_lib
|
18
19
|
from langfun.core.eval.v2 import experiment as experiment_lib
|
@@ -95,7 +96,7 @@ class _TqdmProgressTracker(experiment_lib.Plugin):
|
|
95
96
|
for i, leaf in enumerate(root.leaf_nodes)
|
96
97
|
}
|
97
98
|
summary_link = Experiment.link(
|
98
|
-
runner.current_run.
|
99
|
+
os.path.join(runner.current_run.output_root, 'summary.html')
|
99
100
|
)
|
100
101
|
lf.console.write(f'Summary: {summary_link}.', color='green')
|
101
102
|
|
langfun/core/modalities/mime.py
CHANGED
@@ -152,12 +152,33 @@ class Mime(lf.Modality):
|
|
152
152
|
|
153
153
|
@classmethod
|
154
154
|
def from_uri(cls, uri: str, **kwargs) -> 'Mime':
|
155
|
+
if uri.startswith('data:'):
|
156
|
+
mime_type, content = cls._parse_data_uri(uri)
|
157
|
+
return cls.class_from_mime_type(mime_type).from_bytes(content, **kwargs)
|
158
|
+
|
155
159
|
if cls is Mime:
|
156
160
|
content = cls.download(uri)
|
157
161
|
mime = from_buffer(content, mime=True).lower()
|
158
162
|
return cls.class_from_mime_type(mime)(uri=uri, content=content, **kwargs)
|
159
163
|
return cls(uri=uri, content=None, **kwargs)
|
160
164
|
|
165
|
+
@classmethod
|
166
|
+
def _parse_data_uri(cls, uri: str) -> tuple[str, bytes]:
|
167
|
+
"""Returns the MIME type and content from the given data URI."""
|
168
|
+
assert uri.startswith('data:'), uri
|
169
|
+
mime_end_pos = uri.find(';', 0)
|
170
|
+
if mime_end_pos == -1:
|
171
|
+
raise ValueError(f'Invalid data URI: {uri!r}.')
|
172
|
+
mime_type = uri[5: mime_end_pos].strip().lower()
|
173
|
+
encoding_end_pos = uri.find(',', mime_end_pos + 1)
|
174
|
+
if encoding_end_pos == -1:
|
175
|
+
raise ValueError(f'Invalid data URI: {uri!r}.')
|
176
|
+
encoding = uri[mime_end_pos + 1: encoding_end_pos].strip().lower()
|
177
|
+
if encoding != 'base64':
|
178
|
+
raise ValueError(f'Unsupported encoding: {encoding!r}.')
|
179
|
+
base64_content = uri[encoding_end_pos + 1:].strip().encode()
|
180
|
+
return mime_type, base64.b64decode(base64_content)
|
181
|
+
|
161
182
|
@classmethod
|
162
183
|
def from_bytes(cls, content: bytes | str, **kwargs) -> 'Mime':
|
163
184
|
if cls is Mime:
|
@@ -93,6 +93,22 @@ class CustomMimeTest(unittest.TestCase):
|
|
93
93
|
self.assertEqual(content.to_bytes(), b'bar')
|
94
94
|
self.assertEqual(content.mime_type, 'text/plain')
|
95
95
|
|
96
|
+
content = mime.Mime.from_uri('data:text/plain;base64,Zm9v')
|
97
|
+
self.assertIsNone(content.uri)
|
98
|
+
self.assertEqual(content.mime_type, 'text/plain')
|
99
|
+
self.assertEqual(content.content, b'foo')
|
100
|
+
self.assertEqual(content.content_uri, 'data:text/plain;base64,Zm9v')
|
101
|
+
self.assertEqual(content.embeddable_uri, 'data:text/plain;base64,Zm9v')
|
102
|
+
|
103
|
+
with self.assertRaisesRegex(ValueError, 'Invalid data URI'):
|
104
|
+
mime.Mime.from_uri('data:text/plain')
|
105
|
+
|
106
|
+
with self.assertRaisesRegex(ValueError, 'Invalid data URI'):
|
107
|
+
mime.Mime.from_uri('data:text/plain;abcd')
|
108
|
+
|
109
|
+
with self.assertRaisesRegex(ValueError, 'Unsupported encoding'):
|
110
|
+
mime.Mime.from_uri('data:text/plain;base16,abcd')
|
111
|
+
|
96
112
|
def assert_html_content(self, html, expected):
|
97
113
|
expected = inspect.cleandoc(expected).strip()
|
98
114
|
actual = html.content.strip()
|
@@ -67,7 +67,7 @@ langfun/core/eval/v2/metrics.py,sha256=bl8i6u-ZHRBz4hAc3LzsZ2Dc7ZRQcuTYeUhhH-Gxf
|
|
67
67
|
langfun/core/eval/v2/metrics_test.py,sha256=p4FzLJsE8XAzAQuyP9hfEf9YeKWZ__PO_ue8a9P0-cc,6082
|
68
68
|
langfun/core/eval/v2/progress.py,sha256=azZgssQgNdv3IgjKEaQBuGI5ucFDNbdi02P4z_nQ8GE,10292
|
69
69
|
langfun/core/eval/v2/progress_test.py,sha256=YU7VHzmy5knPZwj9vpBN3rQQH2tukj9eKHkuBCI62h8,2540
|
70
|
-
langfun/core/eval/v2/progress_tracking.py,sha256=
|
70
|
+
langfun/core/eval/v2/progress_tracking.py,sha256=zNhNPGlnJnHELEfFpbTMCSXFn8d1IJ57OOYkfFaBFfM,6097
|
71
71
|
langfun/core/eval/v2/progress_tracking_test.py,sha256=fouMVJkFJqHjbhQJngGLGCmA9x3n0dU4USI2dY163mg,2291
|
72
72
|
langfun/core/eval/v2/reporting.py,sha256=yUIPCAMnp7InIzpv1DDWrcLO-75iiOUTpscj7smkfrA,8335
|
73
73
|
langfun/core/eval/v2/reporting_test.py,sha256=hcPJJaMtPulqERvHYTpId83WXdqDKnnexmULtK7WKwk,5686
|
@@ -112,8 +112,8 @@ langfun/core/modalities/audio.py,sha256=qCrVCX690SG0ps-ZfOtNWvHn_CmdJsmxF7GySScW
|
|
112
112
|
langfun/core/modalities/audio_test.py,sha256=yyGEBYqMXmNs_F2dEtj-PX8HE040vqh-YQppsvdxPw4,2025
|
113
113
|
langfun/core/modalities/image.py,sha256=ovcX8NLBNv8WzxAdhQ-u4VQfHVBkWijRj_oiNwhE9lk,1768
|
114
114
|
langfun/core/modalities/image_test.py,sha256=XMgtJXY75R5eo0CZ222D1QUy57_hESnttmCGWwDLt7k,3824
|
115
|
-
langfun/core/modalities/mime.py,sha256=
|
116
|
-
langfun/core/modalities/mime_test.py,sha256=
|
115
|
+
langfun/core/modalities/mime.py,sha256=Hz6MnxQO_ccgrEryUf7dwyUGYj616I68NshLDK9PC_k,8860
|
116
|
+
langfun/core/modalities/mime_test.py,sha256=n084tOkeKHKMOVblCmi5s8nw4o7VYn3ynqvcrz8ww7c,5977
|
117
117
|
langfun/core/modalities/pdf.py,sha256=mfaeCbUA4JslFVTARiJh8hW7imvL4tLVw9gUhO5bAZA,727
|
118
118
|
langfun/core/modalities/pdf_test.py,sha256=ulZ0FbnlsU0wkrdckJ4ONZPTYRyMPO9Aob1UO6FXygk,1950
|
119
119
|
langfun/core/modalities/video.py,sha256=vI9apcHIHGyp90i34Srg7S3G6IBDtDCk8qiXhwRQmkw,967
|
@@ -148,8 +148,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
148
148
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
149
149
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
150
150
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
151
|
-
langfun-0.1.2.
|
152
|
-
langfun-0.1.2.
|
153
|
-
langfun-0.1.2.
|
154
|
-
langfun-0.1.2.
|
155
|
-
langfun-0.1.2.
|
151
|
+
langfun-0.1.2.dev202503240804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
152
|
+
langfun-0.1.2.dev202503240804.dist-info/METADATA,sha256=hHWiQe8QXhgWGGzK6_DDK7_Sl7Bm99b6TTkLIJI6GV8,7692
|
153
|
+
langfun-0.1.2.dev202503240804.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
154
|
+
langfun-0.1.2.dev202503240804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
155
|
+
langfun-0.1.2.dev202503240804.dist-info/RECORD,,
|
File without changes
|
{langfun-0.1.2.dev202503220803.dist-info → langfun-0.1.2.dev202503240804.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
{langfun-0.1.2.dev202503220803.dist-info → langfun-0.1.2.dev202503240804.dist-info}/top_level.txt
RENAMED
File without changes
|