Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,11 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
from edict_functions import EDICT_editing
|
4 |
from PIL import Image
|
|
|
5 |
|
6 |
-
def greet(name):
|
7 |
-
return "Hello " + name + "!!"
|
8 |
|
9 |
|
10 |
-
def
|
11 |
edit_strength, guidance_scale,
|
12 |
steps=50, mix_weight=0.93, ):
|
13 |
x = Image.fromarray(x)
|
@@ -21,6 +20,42 @@ def edict(x, source_text, edit_text,
|
|
21 |
)[0]
|
22 |
return np.array(return_im)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
iface = gr.Interface(fn=edict, inputs=["image",
|
25 |
gr.Textbox(label="Original Description"),
|
26 |
gr.Textbox(label="Edit Description"),
|
@@ -30,4 +65,4 @@ iface = gr.Interface(fn=edict, inputs=["image",
|
|
30 |
gr.Slider(0, 10, value=3, step=0.5),
|
31 |
],
|
32 |
outputs="image")
|
33 |
-
iface.launch()
|
|
|
2 |
import numpy as np
|
3 |
from edict_functions import EDICT_editing
|
4 |
from PIL import Image
|
5 |
+
from utils import Endpoint, get_token
|
6 |
|
|
|
|
|
7 |
|
8 |
|
9 |
+
def local_edict(x, source_text, edit_text,
|
10 |
edit_strength, guidance_scale,
|
11 |
steps=50, mix_weight=0.93, ):
|
12 |
x = Image.fromarray(x)
|
|
|
20 |
)[0]
|
21 |
return np.array(return_im)
|
22 |
|
23 |
+
|
24 |
+
|
25 |
+
def decode_image(img_obj):
|
26 |
+
img = Image.open(img_obj).convert("RGB")
|
27 |
+
return img
|
28 |
+
|
29 |
+
def edict(x, source_text, edit_text,
|
30 |
+
edit_strength, guidance_scale,
|
31 |
+
steps=50, mix_weight=0.93, ):
|
32 |
+
|
33 |
+
url = endpoint.url
|
34 |
+
url = url + "/api/edit"
|
35 |
+
headers = {
|
36 |
+
"User-Agent": "EDICT HuggingFace Space",
|
37 |
+
"Auth-Token": get_token(),
|
38 |
+
}
|
39 |
+
|
40 |
+
data = {
|
41 |
+
"source_text": source_text,
|
42 |
+
"edit_text": edit_text,
|
43 |
+
"edit_strength": edit_strength,
|
44 |
+
"guidance_scale": guidance_scale,
|
45 |
+
}
|
46 |
+
|
47 |
+
image = encode_image(x)
|
48 |
+
files = {"image": image}
|
49 |
+
|
50 |
+
response = requests.post(url, data=data, files=files, headers=headers)
|
51 |
+
|
52 |
+
if response.status_code == 200:
|
53 |
+
return np.array(decode_image(BytesIO(response.content)))
|
54 |
+
else:
|
55 |
+
return "Error: " + response.text
|
56 |
+
# x = decode_image(response)
|
57 |
+
# return np.array(x)
|
58 |
+
|
59 |
iface = gr.Interface(fn=edict, inputs=["image",
|
60 |
gr.Textbox(label="Original Description"),
|
61 |
gr.Textbox(label="Edit Description"),
|
|
|
65 |
gr.Slider(0, 10, value=3, step=0.5),
|
66 |
],
|
67 |
outputs="image")
|
68 |
+
iface.launch()
|