File size: 1,256 Bytes
238a99c
 
 
5cc2d9c
 
6f72d53
34d5b81
238a99c
2d41cae
238a99c
 
 
 
 
 
 
 
 
788ebe0
238a99c
c5acdc6
 
71e7e13
c927ef2
238a99c
 
788ebe0
 
 
238a99c
 
 
 
 
 
 
 
 
 
 
cd89bfa
238a99c
 
 
946bcbb
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
45
46
47
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/d4p75k87yroni1/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, compression, noise):

    if type(input_img) is not PIL.Image.Image:
        input_img = Image.fromarray(input_img, 'RGB')
    
    payload = {
      "input": {
        "image": convert(input_img),
        "mode": "1",
        "quality": str(compression),
        "noise": str(noise)
      }
    }

    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(io.BytesIO(image_data))
    
    return image

demo = gr.Interface(send_req, [gr.Image(), gr.Slider(0, 100, label="Compression", step=1), gr.Slider(0, 100, label="Noise", step=1)], "image")
if __name__ == "__main__":
    demo.launch()