File size: 1,024 Bytes
238a99c 5cc2d9c 6f72d53 34d5b81 238a99c 6f72d53 238a99c 71e7e13 238a99c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import numpy as np
import gradio as gr
import requests
import io
import base64
import PIL
from PIL import Image
url = "https://api.runpod.ai/v2/scuymosf5t8xne/runsync"
def convert(input_img, quality=85):
buffer = io.BytesIO()
input_img.save(buffer, format="JPEG", quality=quality)
buffer.seek(0)
img_base64 = base64.b64encode(buffer.read()).decode('utf-8')
return img_base64
def send_req(input_img: PIL.Image.Image):
print("type: ", type(input_img))
req = {
"input": {
"image": convert(input_img),
"mode": "1"
}
}
headers = {
"Authorization": "Bearer XWV1ST04C0QLWNVAUSJWI6VJMR7YDJCKJSAR6TPA",
"content-type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
image_data = base64.b64decode(response.json()["output"])
image = Image.open(BytesIO(image_data))
return image
demo = gr.Interface(send_req, gr.Image(), "image")
if __name__ == "__main__":
demo.launch() |