|
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() |