Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,26 +12,6 @@ apply_prod_style(st) # NOTE: Uncomment this for production!
|
|
12 |
def V_SPACE(lines):
|
13 |
for _ in range(lines):
|
14 |
st.write(' ')
|
15 |
-
def image_download_button(pil_image, filename: str, fmt: str, label="Download"):
|
16 |
-
if fmt not in ["jpg", "png"]:
|
17 |
-
raise Exception(f"Unknown image format (Available: {fmt} - case sensitive)")
|
18 |
-
|
19 |
-
pil_format = "JPEG" if fmt == "jpg" else "PNG"
|
20 |
-
file_format = "jpg" if fmt == "jpg" else "png"
|
21 |
-
mime = "image/jpeg/?target=external" if fmt == "jpg" else "image/png/?target=external"
|
22 |
-
|
23 |
-
buf = BytesIO()
|
24 |
-
|
25 |
-
pil_image.save(buf, format=pil_format)
|
26 |
-
|
27 |
-
return st.download_button(
|
28 |
-
label=label,
|
29 |
-
data=buf.getvalue(),
|
30 |
-
file_name=f'{filename}.{file_format}',
|
31 |
-
mime=mime,
|
32 |
-
)
|
33 |
-
|
34 |
-
|
35 |
|
36 |
uploaded_file = st.file_uploader(
|
37 |
label="Upload your photo here",
|
@@ -40,8 +20,6 @@ uploaded_file = st.file_uploader(
|
|
40 |
|
41 |
if uploaded_file is not None:
|
42 |
|
43 |
-
|
44 |
-
|
45 |
in_mode = "Transparent (PNG)"
|
46 |
in_submit = st.button("Submit")
|
47 |
|
@@ -64,8 +42,9 @@ if uploaded_file is not None:
|
|
64 |
with st.expander("Success!", expanded=True):
|
65 |
st.image(img_output)
|
66 |
uploaded_name = os.path.splitext(uploaded_file.name)[0]
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
12 |
def V_SPACE(lines):
|
13 |
for _ in range(lines):
|
14 |
st.write(' ')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
uploaded_file = st.file_uploader(
|
17 |
label="Upload your photo here",
|
|
|
20 |
|
21 |
if uploaded_file is not None:
|
22 |
|
|
|
|
|
23 |
in_mode = "Transparent (PNG)"
|
24 |
in_submit = st.button("Submit")
|
25 |
|
|
|
42 |
with st.expander("Success!", expanded=True):
|
43 |
st.image(img_output)
|
44 |
uploaded_name = os.path.splitext(uploaded_file.name)[0]
|
45 |
+
st.download_button(
|
46 |
+
label="Save Image",
|
47 |
+
data=img_output,
|
48 |
+
file_name=f'{uploaded_name}.png',
|
49 |
+
mime="image/png"
|
50 |
+
)
|