From 50a900c8fe7b9665caeb3f9970b468d374c08a9b Mon Sep 17 00:00:00 2001 From: yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Thu, 16 May 2024 14:51:33 +0800 Subject: [PATCH] chore: replace `funix.hint` with `IPython` --- README.md | 17 +++++++++-------- README.zh-CN.md | 15 ++++++++------- examples/bmi.py | 3 ++- examples/class.py | 6 +++--- examples/multimedia/rgb2gray.py | 2 +- examples/themes/theme_showroom.py | 2 +- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8ef46a8c..c034e588 100644 --- a/README.md +++ b/README.md @@ -152,11 +152,11 @@ class A: self.a = a return f"`self.a` has been initialized to {self.a}" - def update_a(self, b: int) -> str: + def set(self, b: int) -> str: self.a = b return f"`self.a` has been updated to {self.a}" - def print_a(self) -> str: + def get(self) -> str: return f"The value of `self.a` is {self.a}" ``` @@ -464,14 +464,14 @@ More examples in Image: response = client.images.generate(prompt=prompt) return response.data[0].url @@ -493,17 +493,18 @@ def dalle(prompt: str = "a cat") -> Image: examples/multimedia/rgb2gray.py πŸ‘ˆ Toggle me to show source code ```python -import io # Python's native +import io # Python's native import PIL # the Python Image Library -import funix +import IPython +import funix @funix.funix( title="Convert color images to grayscale images", ) -def gray_it(image: funix.hint.BytesImage) -> funix.hint.Image: +def gray_it(image: funix.hint.BytesImage) -> IPython.display.Image: img = PIL.Image.open(io.BytesIO(image)) - gray = PIL.ImageOps.grayscale(img) + gray = PIL.ImageOps.grayscale(img) output = io.BytesIO() gray.save(output, format="PNG") return output.getvalue() diff --git a/README.zh-CN.md b/README.zh-CN.md index 6f70e10b..5df79fa3 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -152,11 +152,11 @@ class A: self.a = a return f"`self.a` has been initialized to {self.a}" - def update_a(self, b: int) -> str: + def set(self, b: int) -> str: self.a = b return f"`self.a` has been updated to {self.a}" - def print_a(self) -> str: + def get(self) -> str: return f"The value of `self.a` is {self.a}" ``` @@ -463,7 +463,7 @@ Link: http://127.0.0.1:3000/hello?secret=8c9f55d0eb74adbb3c87a445ea0ae92f ```python from funix import funix # add line one -from funix.hint import Image # add line two +from IPython.display import Image from openai import OpenAI # pip install openai import os @@ -492,17 +492,18 @@ def dalle(prompt: str = "a cat") -> Image: examples/multimedia/rgb2gray.py πŸ‘ˆ η‚Ήζˆ‘ζŸ₯ηœ‹/攢衷源码 ```python -import io # Python's native +import io # Python's native import PIL # the Python Image Library -import funix +import IPython +import funix @funix.funix( title="Convert color images to grayscale images", ) -def gray_it(image: funix.hint.BytesImage) -> funix.hint.Image: +def gray_it(image: funix.hint.BytesImage) -> IPython.display.Image: img = PIL.Image.open(io.BytesIO(image)) - gray = PIL.ImageOps.grayscale(img) + gray = PIL.ImageOps.grayscale(img) output = io.BytesIO() gray.save(output, format="PNG") return output.getvalue() diff --git a/examples/bmi.py b/examples/bmi.py index f9d510d9..5103bf0c 100644 --- a/examples/bmi.py +++ b/examples/bmi.py @@ -1,5 +1,6 @@ # This example shows how to change display labels for arguments +import IPython.display import funix @funix.funix( @@ -11,6 +12,6 @@ }, show_source=True, ) -def BMI(weight: float, height: float) -> funix.hint.Markdown: +def BMI(weight: float, height: float) -> IPython.display.Markdown: bmi = weight / (height**2) return f"## Your BMI is: \n ### {bmi:.2f}" diff --git a/examples/class.py b/examples/class.py index 1b212d5a..ab324114 100644 --- a/examples/class.py +++ b/examples/class.py @@ -1,5 +1,5 @@ from funix import funix_method, funix_class -from funix.hint import Markdown +from IPython.display import Markdown @funix_class() class A: @@ -8,11 +8,11 @@ def __init__(self, a: int): self.a = a print(f"`self.a` has been initialized to {self.a}") - def update_a(self, b: int) -> Markdown: + def set(self, b: int) -> Markdown: self.a = b return f"`self.a` has been updated to {self.a}" - def print_a(self) -> Markdown: + def get(self) -> Markdown: return f"The value of `self.a` is {self.a}" @staticmethod diff --git a/examples/multimedia/rgb2gray.py b/examples/multimedia/rgb2gray.py index 2a5e99de..da3ff0d9 100644 --- a/examples/multimedia/rgb2gray.py +++ b/examples/multimedia/rgb2gray.py @@ -12,4 +12,4 @@ def gray_it(image: funix.hint.BytesImage) -> IPython.display.Image: gray = PIL.ImageOps.grayscale(img) output = io.BytesIO() gray.save(output, format="PNG") - return output.getvalue() \ No newline at end of file + return output.getvalue() diff --git a/examples/themes/theme_showroom.py b/examples/themes/theme_showroom.py index 750d10b9..7ff8ee52 100644 --- a/examples/themes/theme_showroom.py +++ b/examples/themes/theme_showroom.py @@ -1,5 +1,5 @@ from funix import funix -from funix.hint import StrCode, StrTextarea +from funix.hint import StrCode import IPython