langfun 0.1.2.dev202507150805__py3-none-any.whl → 0.1.2.dev202507160804__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/modalities/audio_test.py +4 -4
- langfun/core/modalities/mime.py +16 -12
- {langfun-0.1.2.dev202507150805.dist-info → langfun-0.1.2.dev202507160804.dist-info}/METADATA +11 -36
- {langfun-0.1.2.dev202507150805.dist-info → langfun-0.1.2.dev202507160804.dist-info}/RECORD +7 -7
- {langfun-0.1.2.dev202507150805.dist-info → langfun-0.1.2.dev202507160804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202507150805.dist-info → langfun-0.1.2.dev202507160804.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202507150805.dist-info → langfun-0.1.2.dev202507160804.dist-info}/top_level.txt +0 -0
@@ -34,8 +34,8 @@ class AudioTest(unittest.TestCase):
|
|
34
34
|
|
35
35
|
def test_audio_content(self):
|
36
36
|
audio = audio_lib.Audio.from_bytes(content_bytes)
|
37
|
-
self.
|
38
|
-
self.
|
37
|
+
self.assertIn(audio.mime_type, ('audio/wave', 'audio/x-wav'))
|
38
|
+
self.assertIn(audio.audio_format, ('wave', 'x-wav'))
|
39
39
|
self.assertEqual(audio.to_bytes(), content_bytes)
|
40
40
|
|
41
41
|
def test_bad_audio(self):
|
@@ -50,8 +50,8 @@ class AudioFileTest(unittest.TestCase):
|
|
50
50
|
audio = audio_lib.Audio.from_uri('http://mock/web/a.wav')
|
51
51
|
with mock.patch('requests.get') as mock_requests_get:
|
52
52
|
mock_requests_get.side_effect = mock_request
|
53
|
-
self.
|
54
|
-
self.
|
53
|
+
self.assertIn(audio.audio_format, ('wave', 'x-wav'))
|
54
|
+
self.assertIn(audio.mime_type, ('audio/wave', 'audio/x-wav'))
|
55
55
|
self.assertEqual(
|
56
56
|
audio._raw_html(),
|
57
57
|
'<audio controls> <source src="http://mock/web/a.wav"> </audio>',
|
langfun/core/modalities/mime.py
CHANGED
@@ -18,18 +18,21 @@ import functools
|
|
18
18
|
from typing import Annotated, Any, Iterable, Type, Union
|
19
19
|
import langfun.core as lf
|
20
20
|
# Placeholder for Google-internal internet access import.
|
21
|
+
import puremagic as pm
|
21
22
|
import pyglove as pg
|
22
23
|
import requests # pylint: disable=unused-import
|
23
24
|
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
def _detect_mime_type(content: bytes) -> str:
|
27
|
+
"""Returns the MIME type from the given content."""
|
28
|
+
try:
|
29
|
+
return pm.from_string(content, mime=True).lower()
|
30
|
+
except pm.PureError:
|
31
|
+
try:
|
32
|
+
content.decode('utf-8')
|
33
|
+
return 'text/plain'
|
34
|
+
except UnicodeDecodeError:
|
35
|
+
return 'application/octet-stream'
|
33
36
|
|
34
37
|
|
35
38
|
class Mime(lf.Modality):
|
@@ -48,7 +51,7 @@ class Mime(lf.Modality):
|
|
48
51
|
@functools.cached_property
|
49
52
|
def mime_type(self) -> str:
|
50
53
|
"""Returns the MIME type."""
|
51
|
-
mime =
|
54
|
+
mime = _detect_mime_type(self.to_bytes())
|
52
55
|
if (
|
53
56
|
self.MIME_PREFIX
|
54
57
|
and not mime.lower().startswith(self.MIME_PREFIX)
|
@@ -160,7 +163,7 @@ class Mime(lf.Modality):
|
|
160
163
|
|
161
164
|
if cls is Mime:
|
162
165
|
content = cls.download(uri)
|
163
|
-
mime =
|
166
|
+
mime = _detect_mime_type(content)
|
164
167
|
return cls.class_from_mime_type(mime)(uri=uri, content=content, **kwargs)
|
165
168
|
return cls(uri=uri, content=None, **kwargs)
|
166
169
|
|
@@ -184,8 +187,9 @@ class Mime(lf.Modality):
|
|
184
187
|
@classmethod
|
185
188
|
def from_bytes(cls, content: bytes | str, **kwargs) -> 'Mime':
|
186
189
|
if cls is Mime:
|
187
|
-
|
188
|
-
|
190
|
+
return cls.class_from_mime_type(
|
191
|
+
_detect_mime_type(content)
|
192
|
+
)(content=content, **kwargs)
|
189
193
|
return cls(content=content, **kwargs)
|
190
194
|
|
191
195
|
@classmethod
|
{langfun-0.1.2.dev202507150805.dist-info → langfun-0.1.2.dev202507160804.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: langfun
|
3
|
-
Version: 0.1.2.
|
3
|
+
Version: 0.1.2.dev202507160804
|
4
4
|
Summary: Langfun: Language as Functions.
|
5
5
|
Home-page: https://github.com/google/langfun
|
6
6
|
Author: Langfun Authors
|
@@ -21,30 +21,28 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries
|
22
22
|
Description-Content-Type: text/markdown
|
23
23
|
License-File: LICENSE
|
24
|
-
Requires-Dist: pyglove>=0.4.5.dev202409110000
|
25
24
|
Requires-Dist: jinja2>=3.1.2
|
25
|
+
Requires-Dist: puremagic>=1.20
|
26
|
+
Requires-Dist: pyglove>=0.4.5.dev202507140812
|
26
27
|
Requires-Dist: requests>=2.31.0
|
27
28
|
Provides-Extra: all
|
28
|
-
Requires-Dist: pyglove>=0.4.5.dev202409110000; extra == "all"
|
29
29
|
Requires-Dist: jinja2>=3.1.2; extra == "all"
|
30
|
+
Requires-Dist: puremagic>=1.20; extra == "all"
|
31
|
+
Requires-Dist: pyglove>=0.4.5.dev202507140812; extra == "all"
|
30
32
|
Requires-Dist: requests>=2.31.0; extra == "all"
|
31
|
-
Requires-Dist: termcolor==1.1.0; extra == "all"
|
32
|
-
Requires-Dist: tqdm>=4.64.1; extra == "all"
|
33
33
|
Requires-Dist: google-auth>=2.16.0; extra == "all"
|
34
|
-
Requires-Dist: python-magic>=0.4.27; extra == "all"
|
35
34
|
Requires-Dist: pillow>=10.0.0; extra == "all"
|
36
|
-
|
37
|
-
Requires-Dist:
|
38
|
-
Requires-Dist: tqdm>=4.64.1; extra == "ui"
|
35
|
+
Requires-Dist: termcolor==1.1.0; extra == "all"
|
36
|
+
Requires-Dist: tqdm>=4.64.1; extra == "all"
|
39
37
|
Provides-Extra: vertexai
|
40
38
|
Requires-Dist: google-auth>=2.16.0; extra == "vertexai"
|
41
39
|
Provides-Extra: mime
|
42
|
-
Requires-Dist: python-magic>=0.4.27; extra == "mime"
|
43
40
|
Requires-Dist: pillow>=10.0.0; extra == "mime"
|
44
|
-
Provides-Extra: mime-auto
|
45
|
-
Requires-Dist: python-magic>=0.4.27; extra == "mime-auto"
|
46
41
|
Provides-Extra: mime-pil
|
47
42
|
Requires-Dist: pillow>=10.0.0; extra == "mime-pil"
|
43
|
+
Provides-Extra: ui
|
44
|
+
Requires-Dist: termcolor==1.1.0; extra == "ui"
|
45
|
+
Requires-Dist: tqdm>=4.64.1; extra == "ui"
|
48
46
|
Dynamic: author
|
49
47
|
Dynamic: author-email
|
50
48
|
Dynamic: classifier
|
@@ -202,37 +200,14 @@ a tag from the list below:
|
|
202
200
|
| all | All Langfun features. |
|
203
201
|
| vertexai | VertexAI access. |
|
204
202
|
| mime | All MIME supports. |
|
205
|
-
| mime-auto | Automatic MIME type detection. |
|
206
203
|
| mime-pil | Image support for PIL. |
|
207
204
|
| ui | UI enhancements |
|
208
205
|
|
209
206
|
For example, to install a nightly build that includes VertexAI access, full
|
210
207
|
modality support, and UI enhancements, use:
|
211
|
-
```
|
212
|
-
pip install langfun[vertexai,mime,ui] --pre
|
213
|
-
```
|
214
|
-
|
215
|
-
### Solving import issue with `libmagic`
|
216
|
-
|
217
|
-
Langfun utilizes `libmagic` for automatic MIME type detection to support
|
218
|
-
multi-modal functionalities. However, `pip install libmagic` may not work
|
219
|
-
out-of-the-box on all operation systems, sometimes leading to an
|
220
|
-
`'ImportError: failed to find libmagic.'` error after Langfun installation.
|
221
|
-
|
222
|
-
If you encounter this error, you will need to follow the recommendations below
|
223
|
-
to fix the installation of `libmagic` library.
|
224
208
|
|
225
|
-
#### OSX
|
226
|
-
|
227
|
-
```
|
228
|
-
conda install conda-forge::libmagic
|
229
209
|
```
|
230
|
-
|
231
|
-
#### Windows:
|
232
|
-
```
|
233
|
-
pip install python-magic
|
234
|
-
pip uninstall python-magic-bin
|
235
|
-
pip install python-magic-bin
|
210
|
+
pip install langfun[vertexai,mime,ui] --pre
|
236
211
|
```
|
237
212
|
|
238
213
|
*Disclaimer: this is not an officially supported Google product.*
|
@@ -117,10 +117,10 @@ langfun/core/memories/conversation_history.py,sha256=KR78PurXTSeqsRK9QG9xM7-f245
|
|
117
117
|
langfun/core/memories/conversation_history_test.py,sha256=2kzAq2pUrbR01Z9jhxviIao52JK4JVjr5iGP8pwGxlU,2156
|
118
118
|
langfun/core/modalities/__init__.py,sha256=rh74vS_oL3XzD83ZJrDzwmW-8jnJHJ3s2_Prmp3ndYQ,1116
|
119
119
|
langfun/core/modalities/audio.py,sha256=qCrVCX690SG0ps-ZfOtNWvHn_CmdJsmxF7GySScWUqY,964
|
120
|
-
langfun/core/modalities/audio_test.py,sha256=
|
120
|
+
langfun/core/modalities/audio_test.py,sha256=tW1vEy-Cumhf-HgDgCxlSNZqgJb2HTgqOixGWLiwOmw,2065
|
121
121
|
langfun/core/modalities/image.py,sha256=9TMO63UHtkimouDb6e1naXWxbK7kRgSGPLzBY26BNk8,1835
|
122
122
|
langfun/core/modalities/image_test.py,sha256=XMgtJXY75R5eo0CZ222D1QUy57_hESnttmCGWwDLt7k,3824
|
123
|
-
langfun/core/modalities/mime.py,sha256=
|
123
|
+
langfun/core/modalities/mime.py,sha256=BSRGMHNM2X6xgYJIbGsqZyZX9JOlebeYa8-QkFEHsCw,8937
|
124
124
|
langfun/core/modalities/mime_test.py,sha256=n084tOkeKHKMOVblCmi5s8nw4o7VYn3ynqvcrz8ww7c,5977
|
125
125
|
langfun/core/modalities/pdf.py,sha256=mfaeCbUA4JslFVTARiJh8hW7imvL4tLVw9gUhO5bAZA,727
|
126
126
|
langfun/core/modalities/pdf_test.py,sha256=ulZ0FbnlsU0wkrdckJ4ONZPTYRyMPO9Aob1UO6FXygk,1950
|
@@ -156,8 +156,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
156
156
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
157
157
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
158
158
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
159
|
-
langfun-0.1.2.
|
160
|
-
langfun-0.1.2.
|
161
|
-
langfun-0.1.2.
|
162
|
-
langfun-0.1.2.
|
163
|
-
langfun-0.1.2.
|
159
|
+
langfun-0.1.2.dev202507160804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
160
|
+
langfun-0.1.2.dev202507160804.dist-info/METADATA,sha256=5XixMFne57tMJoz6n2u8ooamDxd2t7GbJCC2ogM3wgs,7380
|
161
|
+
langfun-0.1.2.dev202507160804.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
162
|
+
langfun-0.1.2.dev202507160804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
163
|
+
langfun-0.1.2.dev202507160804.dist-info/RECORD,,
|
File without changes
|
{langfun-0.1.2.dev202507150805.dist-info → langfun-0.1.2.dev202507160804.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
{langfun-0.1.2.dev202507150805.dist-info → langfun-0.1.2.dev202507160804.dist-info}/top_level.txt
RENAMED
File without changes
|