Spaces:
Paused
Paused
| # =========================== # | |
| # Example API Usage in Python # | |
| # =========================== # | |
| # ======================================== # | |
| # Official Doc for Unity # | |
| # https://github.com/huggingface/unity-api # | |
| # ======================================== # | |
| from gradio_client import Client | |
| from PIL import Image | |
| import base64 | |
| import io | |
| def main(path: str, width: int = 512, height: int = 512): | |
| client = Client("Haoming02/hello-world") | |
| img = Image.open(path) | |
| with io.BytesIO() as buffer: | |
| img.save(buffer, format="PNG") | |
| base64_image = base64.b64encode(buffer.getvalue()).decode() | |
| log, image = client.predict( | |
| image=base64_image, | |
| width=int(width), | |
| height=int(height), | |
| api_name="/resizeImage", | |
| ) | |
| print(log) | |
| image = Image.open(io.BytesIO(base64.b64decode(image))) | |
| image.save("./output.png", optimize=True) | |
| if __name__ == "__main__": | |
| import sys | |
| main(*sys.argv[1:]) | |