Spaces:
Running
Running
muhammadnasar
commited on
Commit
·
c4c02ae
1
Parent(s):
ec10747
Upload 2 files
Browse files- app.py +36 -0
- requirements.txt +45 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import io
|
4 |
+
import base64
|
5 |
+
|
6 |
+
def main():
|
7 |
+
st.title('Image Resizer')
|
8 |
+
|
9 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
10 |
+
|
11 |
+
if uploaded_file is not None:
|
12 |
+
try:
|
13 |
+
img = Image.open(uploaded_file)
|
14 |
+
|
15 |
+
width = st.number_input('Enter the width:', min_value=1)
|
16 |
+
height = st.number_input('Enter the height:', min_value=1)
|
17 |
+
|
18 |
+
if st.button('Resize'):
|
19 |
+
resized_img = img.resize((int(width), int(height)))
|
20 |
+
|
21 |
+
output = io.BytesIO()
|
22 |
+
resized_img.save(output, format='JPEG') # Change format if desired (JPEG, PNG, etc.)
|
23 |
+
st.markdown(get_binary_file_downloader_html(output, 'resized_image.jpg', 'Download Resized Image'), unsafe_allow_html=True)
|
24 |
+
|
25 |
+
except Exception as e:
|
26 |
+
st.error(f"An error occurred: {str(e)}")
|
27 |
+
|
28 |
+
def get_binary_file_downloader_html(bin_file, file_label='File', button_text='Download'):
|
29 |
+
# Helper function to create download link
|
30 |
+
bin_str = bin_file.getvalue()
|
31 |
+
bin_file.close()
|
32 |
+
href = f'data:application/octet-stream;base64,{base64.b64encode(bin_str).decode()}'
|
33 |
+
return f'<a href="{href}" download="{file_label}">{button_text}</a>'
|
34 |
+
|
35 |
+
if __name__ == '__main__':
|
36 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==5.2.0
|
2 |
+
attrs==23.1.0
|
3 |
+
blinker==1.7.0
|
4 |
+
cachetools==5.3.2
|
5 |
+
certifi==2023.11.17
|
6 |
+
charset-normalizer==3.3.2
|
7 |
+
click==8.1.7
|
8 |
+
gitdb==4.0.11
|
9 |
+
GitPython==3.1.40
|
10 |
+
idna==3.6
|
11 |
+
importlib-metadata==6.11.0
|
12 |
+
Jinja2==3.1.2
|
13 |
+
jsonschema==4.20.0
|
14 |
+
jsonschema-specifications==2023.11.2
|
15 |
+
markdown-it-py==3.0.0
|
16 |
+
MarkupSafe==2.1.3
|
17 |
+
mdurl==0.1.2
|
18 |
+
numpy==1.26.2
|
19 |
+
packaging==23.2
|
20 |
+
pandas==2.1.4
|
21 |
+
Pillow==10.1.0
|
22 |
+
protobuf==4.25.1
|
23 |
+
pyarrow==14.0.1
|
24 |
+
pydeck==0.8.1b0
|
25 |
+
Pygments==2.17.2
|
26 |
+
python-dateutil==2.8.2
|
27 |
+
pytz==2023.3.post1
|
28 |
+
referencing==0.32.0
|
29 |
+
requests==2.31.0
|
30 |
+
rich==13.7.0
|
31 |
+
rpds-py==0.15.2
|
32 |
+
six==1.16.0
|
33 |
+
smmap==5.0.1
|
34 |
+
streamlit==1.29.0
|
35 |
+
tenacity==8.2.3
|
36 |
+
toml==0.10.2
|
37 |
+
toolz==0.12.0
|
38 |
+
tornado==6.4
|
39 |
+
typing_extensions==4.9.0
|
40 |
+
tzdata==2023.3
|
41 |
+
tzlocal==5.2
|
42 |
+
urllib3==2.1.0
|
43 |
+
validators==0.22.0
|
44 |
+
watchdog==3.0.0
|
45 |
+
zipp==3.17.0
|