Skip to content

Commit

Permalink
chore: replace funix.hint with IPython
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed May 17, 2024
1 parent 61d5613 commit 50a900c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
```

Expand Down Expand Up @@ -464,14 +464,14 @@ More examples in <a href="https://github.com/TexteaInc/funix-doc/blob/main/Refer

```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
client = OpenAI(api_key=os.environ.get("OPENAI_KEY"))


@funix() # add line three
@funix() # add line two
def dalle(prompt: str = "a cat") -> Image:
response = client.images.generate(prompt=prompt)
return response.data[0].url
Expand All @@ -493,17 +493,18 @@ def dalle(prompt: str = "a cat") -> Image:
<summary><code>examples/multimedia/rgb2gray.py</code> 👈 Toggle me to show source code</summary>

```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()
Expand Down
15 changes: 8 additions & 7 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
```

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -492,17 +492,18 @@ def dalle(prompt: str = "a cat") -> Image:
<summary><code>examples/multimedia/rgb2gray.py</code> 👈 点我查看/收起源码 </summary>

```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()
Expand Down
3 changes: 2 additions & 1 deletion examples/bmi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This example shows how to change display labels for arguments

import IPython.display
import funix

@funix.funix(
Expand All @@ -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}"
6 changes: 3 additions & 3 deletions examples/class.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/multimedia/rgb2gray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
return output.getvalue()
2 changes: 1 addition & 1 deletion examples/themes/theme_showroom.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from funix import funix
from funix.hint import StrCode, StrTextarea
from funix.hint import StrCode
import IPython


Expand Down

0 comments on commit 50a900c

Please sign in to comment.