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