Spaces:
Runtime error
Runtime error
File size: 1,282 Bytes
6bf0cfe d92699e e497feb d92699e e497feb 6bf0cfe d92699e 6bf0cfe 971842a fe00933 a97414f fe00933 a97414f fe00933 d92699e a97414f fe00933 a97414f e497feb a97414f e497feb a97414f e497feb a97414f fe00933 d92699e fe00933 a97414f fe00933 a97414f fe00933 a97414f fe00933 a97414f |
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 48 49 50 51 |
import os
import psutil
import json
import requests
import io
import base64
from time import sleep
import gradio as gr
from PIL import Image, PngImagePlugin
model = "/home/user/app/sd/stable-diffusion-webui/models/Stable-diffusion/"
os.system("/usr/bin/python3 /home/user/app/sd/stable-diffusion-webui/webui.py")
url = "http://0.0.0.0:7860"
payload = {
"prompt": "apple is beautiful",
"steps": 5
}
sleep(5)
response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)
r = response.json()
for i in r['images']:
image = Image.open(io.BytesIO(base64.b64decode(i.split(",",1)[0])))
png_payload = {
"image": "data:image/png;base64," + i
}
response2 = requests.post(url=f'{url}/sdapi/v1/png-info', json=png_payload)
pnginfo = PngImagePlugin.PngInfo()
pnginfo.add_text("parameters", response2.json().get("info"))
image.save('output.png', pnginfo=pnginfo)
##############################################################################################
# def current_working_directoy(cwd, ldir, python_path):
# return os.getcwd(), psutil.net_connections(), os.listdir('/usr/bin')
# iface = gr.Interface(fn=current_working_directoy,
# inputs=["text", "text", "text"], outputs=["text", "text", "text"])
# iface.launch() |