Adnan commited on
Commit
aa13b63
β€’
1 Parent(s): 8de2129

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +137 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import pandas as pd
4
+ from dif import *
5
+ from PIL import Image
6
+ import shutil
7
+
8
+ st.set_page_config(
9
+ page_title="Duplicate Image Finder",
10
+ page_icon="πŸ–Ό",
11
+ layout="wide",
12
+ initial_sidebar_state="auto",
13
+ )
14
+
15
+ @st.cache(persist=True,allow_output_mutation=False,show_spinner=True,suppress_st_warning=True)
16
+ def clean_directory(dir):
17
+ shutil.rmtree(dir)
18
+ os.makedirs(dir)
19
+
20
+ single_folder_upload_path = "single_uploads/"
21
+ multi_folder1_upload_path = "multi_uploads/folder_1/"
22
+ multi_folder2_upload_path = "multi_uploads/folder_2/"
23
+
24
+ clean_directory(single_folder_upload_path)
25
+ clean_directory(multi_folder1_upload_path)
26
+ clean_directory(multi_folder2_upload_path)
27
+
28
+ top_image = Image.open('static/banner_top__.jpg')
29
+ bottom_image = Image.open('static/banner_bottom.png')
30
+
31
+ st.sidebar.image(top_image,use_column_width='auto')
32
+ selection_choice = st.sidebar.selectbox('Search for duplicate Images under? 🎯',["Two Directories","Single Directory"])
33
+ st.sidebar.image(bottom_image,use_column_width='auto')
34
+
35
+ st.title("πŸ‘¨β€πŸ’» Duplicate Image Finder πŸ“·")
36
+ st.info('✨ Supports all popular image formats πŸ“· - PNG, JPG, BMP πŸ˜‰')
37
+
38
+ if selection_choice == "Single Directory":
39
+ uploaded_files = st.file_uploader("Upload Images πŸš€", type=["png","jpg","bmp","jpeg"], accept_multiple_files=True)
40
+ with st.spinner(f"Working... πŸ’«"):
41
+ if uploaded_files:
42
+ for uploaded_file in uploaded_files:
43
+ with open(os.path.join(single_folder_upload_path,uploaded_file.name),"wb") as f:
44
+ f.write((uploaded_file).getbuffer())
45
+
46
+ search = dif("single_uploads/")
47
+
48
+ dup_imgs = [key for key in search.result.keys()]
49
+ low_res_imgs = [str(img.split("/")[-1]) for img in search.lower_quality]
50
+ stats_metrics = [search.stats[key] for key in search.stats.keys()]
51
+ time_metrics = [stats_metrics[2][key] for key in stats_metrics[2].keys()]
52
+
53
+ similarity_grade = str(stats_metrics[3])
54
+ similarity_mse = str(stats_metrics[4])
55
+ total_imgs_searched = str(stats_metrics[5])
56
+ total_imgs_found = str(stats_metrics[6])
57
+ strt_datetime = str(time_metrics[0])+ " " + str(time_metrics[1])
58
+ end_datetime = str(time_metrics[2])+ " " + str(time_metrics[3])
59
+ secs_elapsed = str(time_metrics[-1])
60
+
61
+ df = pd.DataFrame(columns = ['names of duplicate images'])
62
+ df['names of duplicate images'] = dup_imgs
63
+ df['names of lowest quality images'] = low_res_imgs
64
+
65
+ if len(total_imgs_searched) != 0:
66
+ col1, col2, col3 = st.columns(3)
67
+ col1.metric("Total Images Searched", total_imgs_searched)
68
+ col2.metric("Duplicate Images Found", total_imgs_found)
69
+ col3.metric("Lowest Quality Images Found", len(low_res_imgs))
70
+
71
+ col1.metric("Similarity Grade", similarity_grade.title())
72
+ col2.metric("Similarity MSE", similarity_mse)
73
+ col3.metric("Seconds Elapsed", secs_elapsed)
74
+ with col2:
75
+ st.markdown("<br>", unsafe_allow_html=True)
76
+ st.dataframe(df)
77
+
78
+ else:
79
+ st.warning('⚠ Please upload your images! 😯')
80
+
81
+ if selection_choice == "Two Directories":
82
+ main_col1, main_col2 = st.columns(2)
83
+ with main_col1:
84
+ multi_folder1_uploaded_files = st.file_uploader("Upload Images (folder 1)πŸ–Ό", type=["png","jpg","bmp","jpeg"], accept_multiple_files=True)
85
+
86
+ with main_col2:
87
+ multi_folder2_uploaded_files = st.file_uploader("Upload Images (folder 2)πŸ–Ό", type=["png","jpg","bmp","jpeg"], accept_multiple_files=True)
88
+
89
+ with st.spinner(f"Working... πŸ’«"):
90
+ if multi_folder1_uploaded_files and multi_folder2_uploaded_files:
91
+ for uploaded_file in multi_folder1_uploaded_files:
92
+ with open(os.path.join(multi_folder1_upload_path,uploaded_file.name),"wb") as f:
93
+ f.write((uploaded_file).getbuffer())
94
+
95
+ for uploaded_file in multi_folder2_uploaded_files:
96
+ with open(os.path.join(multi_folder2_upload_path,uploaded_file.name),"wb") as f:
97
+ f.write((uploaded_file).getbuffer())
98
+
99
+ search = dif("multi_uploads/folder_1/", "multi_uploads/folder_2/")
100
+
101
+ dup_imgs = [key for key in search.result.keys()]
102
+ low_res_imgs = [str(img.split("/")[-1]) for img in search.lower_quality]
103
+ stats_metrics = [search.stats[key] for key in search.stats.keys()]
104
+ time_metrics = [stats_metrics[2][key] for key in stats_metrics[2].keys()]
105
+
106
+ similarity_grade = str(stats_metrics[3])
107
+ similarity_mse = str(stats_metrics[4])
108
+ total_imgs_searched = str(stats_metrics[5])
109
+ total_imgs_found = str(stats_metrics[6])
110
+ strt_datetime = str(time_metrics[0])+ " " + str(time_metrics[1])
111
+ end_datetime = str(time_metrics[2])+ " " + str(time_metrics[3])
112
+ secs_elapsed = str(time_metrics[-1])
113
+
114
+ df = pd.DataFrame(columns = ['names of duplicate images'])
115
+ df['names of duplicate images'] = dup_imgs
116
+ df['names of lowest quality images'] = low_res_imgs
117
+
118
+ if len(total_imgs_searched) != 0:
119
+ col1, col2, col3 = st.columns(3)
120
+ col1.metric("Total Images Searched", total_imgs_searched)
121
+ col2.metric("Duplicate Images Found", total_imgs_found)
122
+ col3.metric("Lowest Quality Images Found", len(low_res_imgs))
123
+
124
+ col1.metric("Similarity Grade", similarity_grade.title())
125
+ col2.metric("Similarity MSE", similarity_mse)
126
+ col3.metric("Seconds Elapsed", secs_elapsed)
127
+ with col2:
128
+ st.markdown("<br>", unsafe_allow_html=True)
129
+ st.dataframe(df)
130
+ else:
131
+ st.warning('⚠ Please upload your images! 😯')
132
+
133
+
134
+ st.markdown("<br><hr><center>Made with ❀️ by PROXIMA.PK ✨</center><hr>", unsafe_allow_html=True)
135
+
136
+
137
+
requirements.txt ADDED
Binary file (3.99 kB). View file