Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,18 +5,19 @@ from PIL import Image
|
|
| 5 |
from io import BytesIO
|
| 6 |
from streamlit_drawable_canvas import st_canvas
|
| 7 |
|
| 8 |
-
# API information
|
| 9 |
url = "https://api.magicstudio.com/magiceraser/erase"
|
| 10 |
-
access_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGllbnRfaWQiOiIyRGZQSm1sY1BLalBuaGh4ajBxSVpmQktfbS12RFhTc1NMRFNOX1gtZlVVIiwiZXhwIjoxNzI3MTY0MTcyLCJhcHBfbmFtZSI6IjE3NTMwODQiLCJtZXRhZGF0YSI6bnVsbCwiZ3JhbnRfdHlwZSI6ImNyZWQifQ.24oHGH9ial_gqeYrpUbYP68MwYly2ArzXbhbE1hGzQo' # Your
|
| 11 |
|
|
|
|
| 12 |
def image_download_button(pil_image, filename: str, fmt: str, label="Download"):
|
| 13 |
pil_format = "JPEG" if fmt == "jpg" else "PNG"
|
| 14 |
file_format = "jpg" if fmt == "jpg" else "png"
|
| 15 |
mime = "image/jpeg" if fmt == "jpg" else "image/png"
|
| 16 |
-
|
| 17 |
buf = BytesIO()
|
| 18 |
pil_image.save(buf, format=pil_format)
|
| 19 |
-
|
| 20 |
return st.download_button(
|
| 21 |
label=label,
|
| 22 |
data=buf.getvalue(),
|
|
@@ -24,7 +25,7 @@ def image_download_button(pil_image, filename: str, fmt: str, label="Download"):
|
|
| 24 |
mime=mime,
|
| 25 |
)
|
| 26 |
|
| 27 |
-
# Set title of the app
|
| 28 |
st.title("AI Photo Object Removal")
|
| 29 |
|
| 30 |
# Upload the image
|
|
@@ -86,7 +87,7 @@ if uploaded_file is not None:
|
|
| 86 |
('image_file', ('image.png', img_buffer.getvalue(), 'image/png')),
|
| 87 |
('mask_file', ('mask.png', mask_buffer.getvalue(), 'image/png')),
|
| 88 |
]
|
| 89 |
-
|
| 90 |
headers = {
|
| 91 |
'accessToken': access_token
|
| 92 |
}
|
|
@@ -112,6 +113,3 @@ if uploaded_file is not None:
|
|
| 112 |
st.error(f"Error: {response.status_code} - {response.text}")
|
| 113 |
except Exception as e:
|
| 114 |
st.error(f"Error processing the image: {e}")
|
| 115 |
-
if __name__ == "__main__":
|
| 116 |
-
import os
|
| 117 |
-
os.system("streamlit run app.py")
|
|
|
|
| 5 |
from io import BytesIO
|
| 6 |
from streamlit_drawable_canvas import st_canvas
|
| 7 |
|
| 8 |
+
# API information (your actual token)
|
| 9 |
url = "https://api.magicstudio.com/magiceraser/erase"
|
| 10 |
+
access_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGllbnRfaWQiOiIyRGZQSm1sY1BLalBuaGh4ajBxSVpmQktfbS12RFhTc1NMRFNOX1gtZlVVIiwiZXhwIjoxNzI3MTY0MTcyLCJhcHBfbmFtZSI6IjE3NTMwODQiLCJtZXRhZGF0YSI6bnVsbCwiZ3JhbnRfdHlwZSI6ImNyZWQifQ.24oHGH9ial_gqeYrpUbYP68MwYly2ArzXbhbE1hGzQo' # Your token
|
| 11 |
|
| 12 |
+
# Helper function for downloading the processed image
|
| 13 |
def image_download_button(pil_image, filename: str, fmt: str, label="Download"):
|
| 14 |
pil_format = "JPEG" if fmt == "jpg" else "PNG"
|
| 15 |
file_format = "jpg" if fmt == "jpg" else "png"
|
| 16 |
mime = "image/jpeg" if fmt == "jpg" else "image/png"
|
| 17 |
+
|
| 18 |
buf = BytesIO()
|
| 19 |
pil_image.save(buf, format=pil_format)
|
| 20 |
+
|
| 21 |
return st.download_button(
|
| 22 |
label=label,
|
| 23 |
data=buf.getvalue(),
|
|
|
|
| 25 |
mime=mime,
|
| 26 |
)
|
| 27 |
|
| 28 |
+
# Set the title of the app
|
| 29 |
st.title("AI Photo Object Removal")
|
| 30 |
|
| 31 |
# Upload the image
|
|
|
|
| 87 |
('image_file', ('image.png', img_buffer.getvalue(), 'image/png')),
|
| 88 |
('mask_file', ('mask.png', mask_buffer.getvalue(), 'image/png')),
|
| 89 |
]
|
| 90 |
+
|
| 91 |
headers = {
|
| 92 |
'accessToken': access_token
|
| 93 |
}
|
|
|
|
| 113 |
st.error(f"Error: {response.status_code} - {response.text}")
|
| 114 |
except Exception as e:
|
| 115 |
st.error(f"Error processing the image: {e}")
|
|
|
|
|
|
|
|
|