Spaces:
Runtime error
Runtime error
import gradio as gr | |
import numpy as np | |
# from edict_functions import EDICT_editing | |
from PIL import Image | |
from utils import Endpoint, get_token | |
endpoint = Endpoint() | |
def local_edict(x, source_text, edit_text, | |
edit_strength, guidance_scale, | |
steps=50, mix_weight=0.93, ): | |
x = Image.fromarray(x) | |
return_im = EDICT_editing(x, | |
source_text, | |
edit_text, | |
steps=steps, | |
mix_weight=mix_weight, | |
init_image_strength=edit_strength, | |
guidance_scale=guidance_scale | |
)[0] | |
return np.array(return_im) | |
def decode_image(img_obj): | |
img = Image.open(img_obj).convert("RGB") | |
return img | |
def edict(x, source_text, edit_text, | |
edit_strength, guidance_scale, | |
steps=50, mix_weight=0.93, ): | |
url = endpoint.url | |
url = url + "/api/edit" | |
headers = { | |
"User-Agent": "EDICT HuggingFace Space", | |
"Auth-Token": get_token(), | |
} | |
data = { | |
"source_text": source_text, | |
"edit_text": edit_text, | |
"edit_strength": edit_strength, | |
"guidance_scale": guidance_scale, | |
} | |
image = encode_image(x) | |
files = {"image": image} | |
response = requests.post(url, data=data, files=files, headers=headers) | |
if response.status_code == 200: | |
return np.array(decode_image(BytesIO(response.content))) | |
else: | |
return "Error: " + response.text | |
# x = decode_image(response) | |
# return np.array(x) | |
iface = gr.Interface(fn=edict, inputs=["image", | |
gr.Textbox(label="Original Description"), | |
gr.Textbox(label="Edit Description"), | |
# 50, # gr.Slider(5, 50, value=20, step=1), | |
# 0.93, # gr.Slider(0.5, 1, value=0.7, step=0.05), | |
gr.Slider(0.0, 1, value=0.8, step=0.05), | |
gr.Slider(0, 10, value=3, step=0.5), | |
], | |
outputs="image") | |
iface.launch() |