Spaces:
Sleeping
Sleeping
pain
Browse files
app.py
CHANGED
@@ -39,15 +39,17 @@ with gr.Blocks() as demo:
|
|
39 |
|
40 |
return "\n".join(info)
|
41 |
|
42 |
-
#
|
43 |
-
# parameter name is also shown as parameter name in API
|
44 |
-
#
|
45 |
-
|
46 |
-
|
|
|
47 |
|
48 |
-
|
|
|
49 |
|
50 |
-
|
51 |
if os.path.isfile(image):
|
52 |
image = Image.open(image)
|
53 |
else:
|
@@ -55,6 +57,7 @@ with gr.Blocks() as demo:
|
|
55 |
# This works with base64 image via API #
|
56 |
# ==================================== #
|
57 |
image = Image.open(BytesIO(base64.b64decode(image)))
|
|
|
58 |
else:
|
59 |
raise ValueError("Unsupported Image Type")
|
60 |
|
@@ -164,6 +167,10 @@ with gr.Blocks() as demo:
|
|
164 |
api_name="systemInfo",
|
165 |
)
|
166 |
|
|
|
|
|
|
|
|
|
167 |
yeet1.click(
|
168 |
fn=proc_image,
|
169 |
inputs=[foo1, foo2, foo3],
|
@@ -171,6 +178,8 @@ with gr.Blocks() as demo:
|
|
171 |
show_progress="hidden",
|
172 |
show_api=True,
|
173 |
api_name="resizeImage",
|
|
|
|
|
174 |
)
|
175 |
|
176 |
demo.launch(show_error=True)
|
|
|
39 |
|
40 |
return "\n".join(info)
|
41 |
|
42 |
+
# ===================================================== #
|
43 |
+
# parameter name is also shown as parameter name in API #
|
44 |
+
# ===================================================== #
|
45 |
+
def proc_image(
|
46 |
+
image: dict | str, width: int, height: int
|
47 |
+
) -> list[str, Image.Image]:
|
48 |
|
49 |
+
if isinstance(image, dict):
|
50 |
+
image = Image.open(image["path"])
|
51 |
|
52 |
+
elif isinstance(image, str):
|
53 |
if os.path.isfile(image):
|
54 |
image = Image.open(image)
|
55 |
else:
|
|
|
57 |
# This works with base64 image via API #
|
58 |
# ==================================== #
|
59 |
image = Image.open(BytesIO(base64.b64decode(image)))
|
60 |
+
|
61 |
else:
|
62 |
raise ValueError("Unsupported Image Type")
|
63 |
|
|
|
167 |
api_name="systemInfo",
|
168 |
)
|
169 |
|
170 |
+
# ======================================================== #
|
171 |
+
# disable preprocess to allow arbitrary type from API #
|
172 |
+
# Note: parameter type has to be manually handled this way #
|
173 |
+
# ======================================================== #
|
174 |
yeet1.click(
|
175 |
fn=proc_image,
|
176 |
inputs=[foo1, foo2, foo3],
|
|
|
178 |
show_progress="hidden",
|
179 |
show_api=True,
|
180 |
api_name="resizeImage",
|
181 |
+
preprocess=False,
|
182 |
+
postprocess=False,
|
183 |
)
|
184 |
|
185 |
demo.launch(show_error=True)
|