{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.10/dist-packages/torchvision/transforms/functional_tensor.py:5: UserWarning: The torchvision.transforms.functional_tensor module is deprecated in 0.15 and will be **removed in 0.17**. Please don't rely on it. You probably just need to use APIs in torchvision.transforms.functional or in torchvision.transforms.v2.functional.\n", " warnings.warn(\n" ] } ], "source": [ "from handler import EndpointHandler\n", "import base64\n", "from io import BytesIO\n", "from PIL import Image\n", "import cv2\n", "import random\n", "import requests" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'image_url': 'https://jiffy-staging-upscaled-images.s3.amazonaws.com/cfd6161a-4eaa-4077-b4ed-0ad0319508e6.png', 'image_key': 'cfd6161a-4eaa-4077-b4ed-0ad0319508e6.png', 'error': None}\n", "https://jiffy-staging-upscaled-images.s3.amazonaws.com/cfd6161a-4eaa-4077-b4ed-0ad0319508e6.png cfd6161a-4eaa-4077-b4ed-0ad0319508e6.png None\n" ] } ], "source": [ "\n", "API_URL = \"https://uyw9tcuw0ydpsqmw.us-east-1.aws.endpoints.huggingface.cloud\"\n", "headers = {\n", "\t\"Accept\" : \"application/json\",\n", "\t\"Authorization\": \"Bearer hf_XXXX\",\n", " \t\"Content-Type\": \"application/json\",\n", "}\n", "\n", "img_dir = \"test_data/\"\n", "img_urls = [\"https://jiffy-transfers.imgix.net/2/attachments/r267odvvfmkp6c5lccj1y6f9trb0?ixlib=rb-0.3.5\",\n", " # \"https://jiffy-staging-transfers.imgix.net/2/development/attachments/zo31eau0ykhbwoddrjtlbyz6w9mp?ixlib=rb-0.3.5\", # larger than > 1.96M pixels\n", " # \"https://jiffy-staging-transfers.imgix.net/2/development/attachments/b8ecchms9rr9wk3g71kfpfprqg1v?ixlib=rb-0.3.5\" # larger than > 1.96M pixels\n", " ]\n", "out_scales = [3, 3, 2.49]\n", "for img_url, outscale in zip(img_urls, out_scales):\n", "\t# create payload\n", "\tpayload = {\"inputs\": {\"image_url\": img_url, \"outscale\": outscale}}\n", "\t\t\n", "\tresponse = requests.post(API_URL, headers=headers, json=payload)\n", "\toutput_payload = response.json()\t\n", "\tprint(output_payload['image_url'], output_payload['image_key'], output_payload['error'])\n", "\tbreak" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "diffusers", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }