shukdevdatta123 commited on
Commit
761f67f
·
verified ·
1 Parent(s): 2dbfaa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -108
app.py CHANGED
@@ -1,108 +1,115 @@
1
- import streamlit as st
2
- from PIL import Image, ImageFilter
3
- import io
4
- import zipfile
5
- import time
6
-
7
- def apply_filters(image):
8
- """Apply various filters to the image."""
9
- filters = {
10
- "Detail": ImageFilter.DETAIL,
11
- "Edge Enhance": ImageFilter.EDGE_ENHANCE,
12
- "Edge Enhance More": ImageFilter.EDGE_ENHANCE_MORE,
13
- "Smooth": ImageFilter.SMOOTH,
14
- "Smooth More": ImageFilter.SMOOTH_MORE,
15
- "Sharpen": ImageFilter.SHARPEN
16
- }
17
-
18
- filtered_images = {}
19
- for filter_name, filter_type in filters.items():
20
- filtered_images[filter_name] = image.filter(filter_type)
21
- return filtered_images
22
-
23
- # Streamlit UI
24
- st.title("Face Filtering App")
25
-
26
- # Instructions sidebar
27
- with st.sidebar:
28
- st.header("Instructions")
29
- st.write(
30
- "1) If you choose only one image to upload, the results will be shown on display, and you can click the 'Download Processed Images' button to download the processed images in zip format.\n"
31
- "2) If you choose more than one image, it will not display any image as results; instead, it will directly show you the 'Download Processed Images' button, and you can click on it to download the processed images in zip format."
32
- )
33
-
34
- uploaded_files = st.file_uploader("Choose images", accept_multiple_files=True, type=["jpg", "jpeg", "png"])
35
-
36
- if st.button("Process Images"):
37
- if uploaded_files:
38
- processed_images = []
39
-
40
- # Create a progress bar
41
- progress_bar = st.progress(0)
42
-
43
- # Show a spinner while processing images
44
- for idx, uploaded_file in enumerate(uploaded_files):
45
- image = Image.open(uploaded_file)
46
-
47
- # Show original image if only one file is uploaded
48
- if len(uploaded_files) == 1:
49
- st.image(image, caption=f"Original Image: {uploaded_file.name}", use_column_width=True)
50
-
51
- # Apply filters
52
- filtered_images = apply_filters(image)
53
- for filter_name, filtered_image in filtered_images.items():
54
- if len(uploaded_files) == 1:
55
- st.image(filtered_image, caption=f"{filter_name} Filter", use_column_width=True)
56
-
57
- # Save each filtered image to a temporary in-memory buffer
58
- buffered = io.BytesIO()
59
- filtered_image.save(buffered, format="PNG")
60
- processed_images.append((f"{uploaded_file.name.split('.')[0]}_{filter_name}.png", buffered.getvalue()))
61
-
62
- # Update progress bar
63
- progress = (idx + 1) / len(uploaded_files)
64
- progress_bar.progress(progress)
65
-
66
- # Simulate processing time
67
- time.sleep(0.1)
68
-
69
- # Create a zip file for download
70
- zip_buffer = io.BytesIO()
71
- with zipfile.ZipFile(zip_buffer, 'w') as zip_file:
72
- for filename, img_data in processed_images:
73
- zip_file.writestr(filename, img_data)
74
-
75
- zip_buffer.seek(0)
76
-
77
- # Provide a download button for the zip file
78
- st.download_button(
79
- label="Download Processed Images",
80
- data=zip_buffer,
81
- file_name="processed_images.zip",
82
- mime="application/zip"
83
- )
84
-
85
- # Show balloon pop-up when processing is complete
86
- st.balloons()
87
-
88
- else:
89
- st.warning("Please upload at least one image.")
90
-
91
- # Copyright notice
92
- st.markdown(
93
- """
94
- <style>
95
- .copyright {
96
- position: fixed;
97
- bottom: 10px;
98
- right: 10px;
99
- font-size: 18px;
100
- color: #0F81C9;
101
- }
102
- </style>
103
- <div class="copyright">
104
- Copyright: [email protected]
105
- </div>
106
- """,
107
- unsafe_allow_html=True
108
- )
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image, ImageFilter
3
+ import io
4
+ import zipfile
5
+ import time
6
+
7
+ def apply_filters(image):
8
+ """Apply various filters to the image."""
9
+ filters = {
10
+ "Detail": ImageFilter.DETAIL,
11
+ "Edge Enhance": ImageFilter.EDGE_ENHANCE,
12
+ "Edge Enhance More": ImageFilter.EDGE_ENHANCE_MORE,
13
+ "Smooth": ImageFilter.SMOOTH,
14
+ "Smooth More": ImageFilter.SMOOTH_MORE,
15
+ "Sharpen": ImageFilter.SHARPEN
16
+ }
17
+
18
+ filtered_images = {}
19
+ for filter_name, filter_type in filters.items():
20
+ filtered_images[filter_name] = image.filter(filter_type)
21
+ return filtered_images
22
+
23
+ # Streamlit UI
24
+ st.title("Face Filtering App")
25
+
26
+ # Modal Popup for Instructions
27
+ with st.expander("Learn about Face Filtering", expanded=True):
28
+ st.write(
29
+ "Face filtering is a creative technique that enhances images by applying various effects to highlight different features of the subject. The filters available in this app include Detail, which sharpens textures and makes features stand out; Edge Enhance and Edge Enhance More, which accentuate edges for a defined look; Smooth and Smooth More, which soften the image and reduce imperfections for a polished appearance; and Sharpen, which increases contrast and clarity to reveal finer details. Together, these filters allow users to transform their photos, emphasizing beauty and enabling unique artistic interpretations, making face filtering an engaging way to manipulate images and express creativity."
30
+ )
31
+
32
+ # Instructions sidebar
33
+ with st.sidebar:
34
+ st.header("Instructions")
35
+ st.write(
36
+ "1) If you choose only one image to upload, the results will be shown on display, and you can click the 'Download Processed Images' button to download the processed images in zip format.\n"
37
+ "2) If you choose more than one image, it will not display any image as results; instead, it will directly show you the 'Download Processed Images' button, and you can click on it to download the processed images in zip format."
38
+ )
39
+
40
+ # Image uploader
41
+ uploaded_files = st.file_uploader("Choose images", accept_multiple_files=True, type=["jpg", "jpeg", "png"])
42
+
43
+ if st.button("Process Images"):
44
+ if uploaded_files:
45
+ processed_images = []
46
+
47
+ # Create a progress bar
48
+ progress_bar = st.progress(0)
49
+
50
+ # Show a spinner while processing images
51
+ for idx, uploaded_file in enumerate(uploaded_files):
52
+ image = Image.open(uploaded_file)
53
+
54
+ # Show original image if only one file is uploaded
55
+ if len(uploaded_files) == 1:
56
+ st.image(image, caption=f"Original Image: {uploaded_file.name}", use_column_width=True)
57
+
58
+ # Apply filters
59
+ filtered_images = apply_filters(image)
60
+ for filter_name, filtered_image in filtered_images.items():
61
+ if len(uploaded_files) == 1:
62
+ st.image(filtered_image, caption=f"{filter_name} Filter", use_column_width=True)
63
+
64
+ # Save each filtered image to a temporary in-memory buffer
65
+ buffered = io.BytesIO()
66
+ filtered_image.save(buffered, format="PNG")
67
+ processed_images.append((f"{uploaded_file.name.split('.')[0]}_{filter_name}.png", buffered.getvalue()))
68
+
69
+ # Update progress bar
70
+ progress = (idx + 1) / len(uploaded_files)
71
+ progress_bar.progress(progress)
72
+
73
+ # Simulate processing time
74
+ time.sleep(0.1)
75
+
76
+ # Create a zip file for download
77
+ zip_buffer = io.BytesIO()
78
+ with zipfile.ZipFile(zip_buffer, 'w') as zip_file:
79
+ for filename, img_data in processed_images:
80
+ zip_file.writestr(filename, img_data)
81
+
82
+ zip_buffer.seek(0)
83
+
84
+ # Provide a download button for the zip file
85
+ st.download_button(
86
+ label="Download Processed Images",
87
+ data=zip_buffer,
88
+ file_name="processed_images.zip",
89
+ mime="application/zip"
90
+ )
91
+
92
+ # Show balloon pop-up when processing is complete
93
+ st.balloons()
94
+
95
+ else:
96
+ st.warning("Please upload at least one image.")
97
+
98
+ # Copyright notice
99
+ st.markdown(
100
+ """
101
+ <style>
102
+ .copyright {
103
+ position: fixed;
104
+ bottom: 10px;
105
+ right: 10px;
106
+ font-size: 18px;
107
+ color: #0F81C9;
108
+ }
109
+ </style>
110
+ <div class="copyright">
111
+ Copyright: [email protected]
112
+ </div>
113
+ """,
114
+ unsafe_allow_html=True
115
+ )