langfun 0.1.1.dev20240721__py3-none-any.whl → 0.1.1.dev20240724__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.
@@ -29,6 +29,7 @@ from langfun.core.llms.rest import REST
29
29
 
30
30
  # Gemini models.
31
31
  from langfun.core.llms.google_genai import GenAI
32
+ from langfun.core.llms.google_genai import GeminiFlash1_5
32
33
  from langfun.core.llms.google_genai import GeminiPro
33
34
  from langfun.core.llms.google_genai import GeminiPro1_5
34
35
  from langfun.core.llms.google_genai import GeminiProVision
@@ -15,6 +15,7 @@
15
15
 
16
16
  import functools
17
17
  import io
18
+
18
19
  from langfun.core.modalities import mime
19
20
  from PIL import Image as pil_image
20
21
 
@@ -31,6 +32,16 @@ class Image(mime.Mime):
31
32
  def _html(self, uri: str) -> str:
32
33
  return f'<img src="{uri}">'
33
34
 
35
+ @functools.cached_property
34
36
  def size(self) -> tuple[int, int]:
35
37
  img = pil_image.open(io.BytesIO(self.to_bytes()))
36
38
  return img.size
39
+
40
+ def to_pil_image(self) -> pil_image.Image:
41
+ return pil_image.open(io.BytesIO(self.to_bytes()))
42
+
43
+ @classmethod
44
+ def from_pil_image(cls, img: pil_image.Image) -> 'Image':
45
+ buf = io.BytesIO()
46
+ img.save(buf, format='PNG')
47
+ return cls.from_bytes(buf.getvalue())
@@ -12,12 +12,14 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  """Image tests."""
15
+ import io
15
16
  import unittest
16
17
  from unittest import mock
17
18
 
18
19
  import langfun.core as lf
19
20
  from langfun.core.modalities import image as image_lib
20
21
  from langfun.core.modalities import mime as mime_lib
22
+ import PIL.Image as pil_image
21
23
  import pyglove as pg
22
24
 
23
25
 
@@ -81,7 +83,19 @@ class ImageTest(unittest.TestCase):
81
83
  image = image_lib.Image.from_uri('http://mock/web/a.png')
82
84
  with mock.patch('requests.get') as mock_requests_get:
83
85
  mock_requests_get.side_effect = mock_request
84
- self.assertEqual(image.size(), (24, 24))
86
+ self.assertEqual(image.size, (24, 24))
87
+
88
+ def test_to_pil_image(self):
89
+ image = image_lib.Image.from_uri('http://mock/web/a.png')
90
+ with mock.patch('requests.get') as mock_requests_get:
91
+ mock_requests_get.side_effect = mock_request
92
+ self.assertIsInstance(image.to_pil_image(), pil_image.Image)
93
+
94
+ def test_from_pil_image(self):
95
+ image = pil_image.open(io.BytesIO(image_content))
96
+ self.assertIsInstance(
97
+ image_lib.Image.from_pil_image(image), image_lib.Image
98
+ )
85
99
 
86
100
 
87
101
  if __name__ == '__main__':
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.1.1.dev20240721
3
+ Version: 0.1.1.dev20240724
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -26,14 +26,14 @@ Requires-Dist: google-generativeai >=0.3.2
26
26
  Requires-Dist: jinja2 >=3.1.2
27
27
  Requires-Dist: openai ==0.27.2
28
28
  Requires-Dist: openpyxl >=3.1.0
29
- Requires-Dist: pandas >=2.1.4
29
+ Requires-Dist: pandas >=2.0.3
30
30
  Requires-Dist: pyglove >=0.4.5.dev20240423
31
31
  Requires-Dist: python-docx >=0.8.11
32
32
  Requires-Dist: python-magic >=0.4.27
33
33
  Requires-Dist: requests >=2.31.0
34
34
  Requires-Dist: termcolor ==1.1.0
35
35
  Requires-Dist: tqdm >=4.64.1
36
- Requires-Dist: pillow >=10.1.0
36
+ Requires-Dist: pillow >=10.0.0
37
37
 
38
38
  <div align="center">
39
39
  <img src="https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg" width="520px" alt="logo"></img>
@@ -52,7 +52,7 @@ langfun/core/eval/patching.py,sha256=R0s2eAd1m97exQt06dmUL0V_MBG0W2Hxg7fhNB7cXW0
52
52
  langfun/core/eval/patching_test.py,sha256=8kCd54Egjju22FMgtJuxEsrXkW8ifs-UUBHtrCG1L6w,4775
53
53
  langfun/core/eval/scoring.py,sha256=1J7IATo-8FXUR0SBqk9icztHiM0lWkBFcWUo-vUURgQ,6376
54
54
  langfun/core/eval/scoring_test.py,sha256=O8olHbrUEg60gMxwOkWzKBJZpZoUlmVnBANX5Se2SXM,4546
55
- langfun/core/llms/__init__.py,sha256=3OA4uQczFEKHoIUcWDO3myesdeDISLUWJ8fjp6zjGww,4551
55
+ langfun/core/llms/__init__.py,sha256=sRD_PjfD5wKuzANCOCjChjuZHUn2Q1WruZeVflqej5M,4609
56
56
  langfun/core/llms/anthropic.py,sha256=Gon3fOi31RhZFgNd0ijyTnKnUdp9hrWrCoSXyO4UaLw,7316
57
57
  langfun/core/llms/anthropic_test.py,sha256=T-swuMkfnlgs8Fpif4rtXs579exGk0TsbLMirXDZCkg,5533
58
58
  langfun/core/llms/fake.py,sha256=Dd7-6ka9pFf3fcWZyczamjOqQ91MOI-m7We3Oc9Ffmo,2927
@@ -79,8 +79,8 @@ langfun/core/memories/conversation_history_test.py,sha256=AaW8aNoFjxNusanwJDV0r3
79
79
  langfun/core/modalities/__init__.py,sha256=F8P72IwFiTpEseTR2tYEJyQMlDW7fd9csvGJquLKJNg,1269
80
80
  langfun/core/modalities/audio.py,sha256=Qxo7bYjLKQ1gVJVomr9RqR2SvxY826QgXhTzzk437Sk,952
81
81
  langfun/core/modalities/audio_test.py,sha256=gWCB9h3FyrdGqro3ajBXqkw0lU0W1sBjOOq6wZbl7Fg,2027
82
- langfun/core/modalities/image.py,sha256=sMMmjNYUTdPViDOqc93WtSFrzE1-GRrEv-6I3eb8iYY,1083
83
- langfun/core/modalities/image_test.py,sha256=Rcq4b77E9-Vp6rhqJ5ZIh0yJkEtcJbZZwjTjlu9dx8E,3282
82
+ langfun/core/modalities/image.py,sha256=uBSAwExnSD4MevhK9Z4qExPlLVFBQLUfjPOAldtWFOI,1387
83
+ langfun/core/modalities/image_test.py,sha256=A0aYblxpnKABDgm2OVPxF8iRq4qFVanM9TPcaewkAgA,3774
84
84
  langfun/core/modalities/mime.py,sha256=7oYvwYZHb3uhjiL2rF6kvQWsWufY0UXl72wfDXC59ys,5918
85
85
  langfun/core/modalities/mime_test.py,sha256=kmRiPP-3Py02NnKPu0oPexSIJ-MXaaE2UYY82ga0TV8,2913
86
86
  langfun/core/modalities/ms_office.py,sha256=jOidMSdWCaV9RILpGz8VJkpTSpHJNoirD53jzQvcytM,3388
@@ -117,8 +117,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
117
117
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
118
118
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
119
119
  langfun/core/templates/selfplay_test.py,sha256=rBW2Qr8yi-aWYwoTwRR-n1peKyMX9QXPZXURjLgoiRs,2264
120
- langfun-0.1.1.dev20240721.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
121
- langfun-0.1.1.dev20240721.dist-info/METADATA,sha256=e9k1GL8sFT6ZMYB965oqZPNNzB8bSQp7O7KAc_HKzao,5247
122
- langfun-0.1.1.dev20240721.dist-info/WHEEL,sha256=rWxmBtp7hEUqVLOnTaDOPpR-cZpCDkzhhcBce-Zyd5k,91
123
- langfun-0.1.1.dev20240721.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
124
- langfun-0.1.1.dev20240721.dist-info/RECORD,,
120
+ langfun-0.1.1.dev20240724.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
121
+ langfun-0.1.1.dev20240724.dist-info/METADATA,sha256=XZS-DIas-Z5Pyn39RVPGQwkHqp3OshgQAHoBtipbI-Q,5247
122
+ langfun-0.1.1.dev20240724.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
123
+ langfun-0.1.1.dev20240724.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
124
+ langfun-0.1.1.dev20240724.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (71.0.4)
2
+ Generator: setuptools (71.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5