File size: 11,158 Bytes
575adcc 9ef1ac7 575adcc b4b93bb 575adcc 9ef1ac7 575adcc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
import streamlit as st
import streamlit.components.v1 as stc
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from PIL import Image
import exifread # Extracts Meta data of images
import os
from datetime import datetime
import mutagen # Extracts Meta data of Audio
from PIL.ExifTags import TAGS, GPSTAGS
import base64
import time
from PyPDF2 import PdfReader
timestr = time.strftime("%Y%m%d-%H%M%S")
details = """
Metadata is defined as the data providing information about one or more aspects of the data; it is used to summarize basic information about data which can make tracking and working with specific data easier
"""
HTML_BANNER = """
<div style="background-color:violet;padding:10px;border-radius:10px">
<h1 style="color:white;text-align:center;">MetaData Extractor App </h1>
</div>
"""
def file_download(data):
csv_file= data.to_csv()
b64=base64.b64encode(csv_file.encode()).decode()
new_filename="result_{}.csv".format(timestr)
st.markdown('### ποΈ Download csv file ')
href=f'<a href="data:file/csv;base64,{b64}" download="{new_filename}"> Click Here! </a>'
st.markdown(href, unsafe_allow_html=True)
def view_all_data():
c.execute('SELECT * FROM filestable')
data = c.fetchall()
return data
def load_image(file):
img = Image.open(file)
return img
def get_readable_time(time):
return datetime.fromtimestamp(time).strftime('%Y-%m-%d-%H:%M')
def get_exif(filename):
exif = Image.open(filename).getexif()
if exif is not None and isinstance(exif, dict):
for key, value in exif.items():
name = TAGS.get(key, value)
exif[name] = exif.pop(key)
if 'GPSInfo' in exif:
for key in exif['GPSInfo'].keys():
name = GPSTAGS.get(key,key)
exif['GPSInfo'][name] = exif['GPSInfo'].pop(key)
return exif
def metadata():
# st.title('Meta-Data Extractor App')
stc.html(HTML_BANNER)
menu=['Home','Image','Audio','Document_Files','Analytics']
choice=st.sidebar.selectbox('Menu',menu)
if choice=='Home':
st.image(load_image('extraction_process.png'))
st.write(details)
col1, col2, col3 = st.columns(3)
with col1:
with st.expander("Get Image Metadata π·"):
st.info("Image Metadata")
st.markdown("π·")
st.text("Upload JPEG,JPG,PNG Images")
with col2:
with st.expander("Get Audio Metadata π"):
st.info("Audio Metadata")
st.markdown("π")
st.text("Upload Mp3,Ogg")
with col3:
with st.expander("Get Document Metadata ππ"):
st.info("Document Files Metadata")
st.markdown("ππ")
st.text("Upload PDF,Docx")
elif choice=='Image':
st.subheader('Image MetaData Extractor')
image_file = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg"])
if image_file is not None:
with st.expander('File Stats'):
file_details={'Filename':image_file.name,
'Filesize':image_file.size,
'Filetype':image_file.type}
statinfo=os.stat(image_file.readable())
statdetails={
'Accessed Time': get_readable_time(statinfo.st_atime),
'Creation Time':get_readable_time(statinfo.st_ctime),
'Modified Time':get_readable_time(statinfo.st_mtime)}
full_details={
'Filename':image_file.name,
'Filesize':image_file.size,
'Filetype':image_file.type,
'Accessed Time': get_readable_time(statinfo.st_atime),
'Creation Time':get_readable_time(statinfo.st_ctime),
'Modified Time':get_readable_time(statinfo.st_mtime)
}
# st.write(full_details)
file_details_df = pd.DataFrame(
list(full_details.items()), columns=["Meta Tags", "Value"]
)
st.dataframe(file_details_df)
c1, c2 = st.columns(2)
with c1:
with st.expander("View Image"):
img = load_image(image_file)
st.image(img,width=250)
with c2:
with st.expander("Default(JPEG)"):
st.info("Using PILLOW")
img = load_image(image_file)
img_details = {
"format": img.format,
"format_desc": img.format_description,
"filename": img.filename,
"size": img.size,
"height": img.height,
"width": img.width,
"info": img.info,
}
df_img_details = pd.DataFrame(
list(img_details.items()), columns=["Meta Tags", "Value"]
)
st.dataframe(df_img_details)
c3,c4=st.columns(2)
with c3:
with st.expander('Using ExifRead Tool'):
meta_data=exifread.process_file(image_file)
# st.write(meta_data)
meta_data_df=pd.DataFrame(
list(meta_data.items()),columns=['Meta Data','Values'])
st.dataframe(meta_data_df)
with c4:
with st.expander('Image geo Coordinates'):
img_gps_details=get_exif(image_file)
latitude = img_gps_details.get('GPSLatitude')
longitude = img_gps_details.get('GPSLongitude')
try:
gps_info = img_gps_details
lat=latitude
long=longitude
except:
gps_info = "None Found"
st.write(gps_info)
st.write(lat)
st.write(long)
with st.expander('Download Results'):
final_df=pd.concat([file_details_df,df_img_details,meta_data_df])
st.dataframe(final_df)
file_download(final_df)
elif choice=='Audio':
st.subheader('Audio MetaData Extractor')
audio_file = st.file_uploader("Upload Audio", type=["mp3", "ogg"])
if audio_file is not None:
col1, col2 = st.columns(2)
with col1:
st.audio(audio_file.read())
with col2:
with st.expander("File Stats"):
file_details = {
"FileName": audio_file.name,
"FileSize": audio_file.size,
"FileType": audio_file.type,
}
st.write(file_details)
statinfo = os.stat(audio_file.readable())
stats_details = {
"Accessed_Time": get_readable_time(statinfo.st_atime),
"Creation_Time": get_readable_time(statinfo.st_ctime),
"Modified_Time": get_readable_time(statinfo.st_mtime),
}
st.write(stats_details)
file_details_combined = {
"FileName": audio_file.name,
"FileSize": audio_file.size,
"FileType": audio_file.type,
"Accessed_Time": get_readable_time(statinfo.st_atime),
"Creation_Time": get_readable_time(statinfo.st_ctime),
"Modified_Time": get_readable_time(statinfo.st_mtime),
}
df_file_details = pd.DataFrame(
list(file_details_combined.items()),
columns=["Meta Tags", "Value"],
)
st.dataframe(df_file_details)
with st.expander('Metadata using Mutagen'):
meta_data=mutagen.File(audio_file)
meta_data_dict={str(key):str(value) for key,value in meta_data.items()}
meta_data_audio_df=pd.DataFrame(
list(meta_data_dict.items()),columns=['Tag','Values'])
st.dataframe(meta_data_audio_df)
with st.expander("Download Results"):
combined_df = pd.concat([df_file_details, meta_data_audio_df])
st.dataframe(combined_df)
file_download(combined_df)
elif choice=='Document_Files':
st.subheader('Document MetaData Extractor')
text_file = st.file_uploader("Upload File", type=["PDF"])
if text_file is not None:
col1, col2 = st.columns([1, 2])
with col1:
with st.expander("File Stats"):
file_details = {
"FileName": text_file.name,
"FileSize": text_file.size,
"FileType": text_file.type,
}
st.write(file_details)
statinfo = os.stat(text_file.readable())
stats_details = {
"Accessed_Time": get_readable_time(statinfo.st_atime),
"Creation_Time": get_readable_time(statinfo.st_ctime),
"Modified_Time": get_readable_time(statinfo.st_mtime),
}
st.write(stats_details)
# Combine All Details
file_details_combined = {
"FileName": text_file.name,
"FileSize": text_file.size,
"FileType": text_file.type,
"Accessed_Time": get_readable_time(statinfo.st_atime),
"Creation_Time": get_readable_time(statinfo.st_ctime),
"Modified_Time": get_readable_time(statinfo.st_mtime),
}
# Convert to DataFrame
df_file_details = pd.DataFrame(
list(file_details_combined.items()),
columns=["Meta Tags", "Value"],
)
with col2:
with st.expander("Metadata"):
pdf_file = PdfReader(text_file)
pdf_info = pdf_file.metadata
df_file_details_with_pdf = pd.DataFrame(
list(pdf_info.items()), columns=["Meta Tags", "Value"]
)
st.dataframe(df_file_details_with_pdf)
with st.expander("Download Results"):
pdf_combined_df = pd.concat([df_file_details, df_file_details_with_pdf])
st.dataframe(pdf_combined_df)
file_download(pdf_combined_df)
|