Spaces:
Runtime error
Runtime error
| # !pip install altair | |
| # !pip install piexif | |
| import streamlit as st | |
| from PIL import Image, ExifTags | |
| import pandas as pd | |
| import piexif | |
| import os | |
| # st.title("EXIF data Checker App") | |
| st.write("EXIF (Exchangeable Image File Format) data is metadata that is embedded within an image file. It provides additional information about the image, such as camera settings, device information, date and time the photo was taken, GPS coordinates, and more.") | |
| st.write("EXIF data is automatically recorded by digital cameras and other devices that capture images. It can be useful for various purposes, such as organizing and categorizing photos, understanding the camera settings used for a particular image, and extracting location information.") | |
| st.write("Common examples of EXIF data include:") | |
| st.write("- Camera make and model") | |
| st.write("- Aperture value") | |
| st.write("- Shutter speed") | |
| st.write("- ISO sensitivity") | |
| st.write("- Focal length") | |
| st.write("- Date and time the photo was taken") | |
| st.write("- GPS coordinates (if available)") | |
| st.write("By analyzing the EXIF data of an image, you can gain insights into how the photo was captured and potentially extract valuable information for further analysis or processing.") | |
| st.sidebar.title('EXIF data Checker App!!') | |
| # st.sidebar.write('Created by Sabir Bagwan') | |
| st.sidebar.write('Created by <strong><em>SABIR BAGWAN</em></strong>', unsafe_allow_html=True) | |
| # Display social media links in sidebar | |
| st.sidebar.markdown("[Twitter](https://twitter.com/sabirbagwan_), \ | |
| [LinkedIn](https://www.linkedin.com/in/sabirbagwan/), \ | |
| [GitHub](https://github.com/sabirbagwan), \ | |
| [Kaggle](https://kaggle.com/sabirbagwan)") | |
| st.sidebar.header("Disclaimer:") | |
| st.sidebar.write("This Streamlit application has been created solely for academic and learning purposes. \ | |
| The results and insights provided by the application should not be taken as accurate or definitive. \ | |
| The creator of this application is not responsible for any actions taken based on the information provided by the application.") | |
| # Function to get the description of an EXIF tag | |
| def get_exif_tag_description(tag_id): | |
| tag_description = ExifTags.TAGS.get(tag_id, tag_id) | |
| return tag_description | |
| # Streamlit app | |
| def main(): | |
| st.write("Upload a photo and perform checks.") | |
| # File uploader | |
| photo = st.file_uploader("Upload a photo", type=["jpg", "jpeg", "png"]) | |
| if photo is not None: | |
| # Open the photo using PIL | |
| img = Image.open(photo) | |
| # Display the photo in a centered container | |
| st.markdown( | |
| '<div style="display: flex; justify-content: center;">' | |
| '<img src="data:image/png;base64,{}" alt="Uploaded Photo" height="500">' | |
| '</div>'.format(image_to_base64(img)), | |
| unsafe_allow_html=True | |
| ) | |
| # Check if EXIF data exists | |
| exifdata = img._getexif() | |
| if exifdata: | |
| st.subheader("EXIF data:") | |
| # Prepare data for the table | |
| exif_table = [] | |
| for tag_id, data in exifdata.items(): | |
| # Get the description of the EXIF tag | |
| tag_description = get_exif_tag_description(tag_id) | |
| # Decode GPS coordinates if available | |
| if isinstance(data, bytes): | |
| try: | |
| data = data.decode('utf-8') | |
| except UnicodeDecodeError: | |
| data = data.decode('latin-1') | |
| exif_table.append((tag_description, data)) | |
| # Create a DataFrame from the EXIF data | |
| exif_df = pd.DataFrame(exif_table, columns=['Tag', 'Data']) | |
| # Display the EXIF data in a table | |
| st.table(exif_df) | |
| image = img.convert('RGB') | |
| # Remove all exif data | |
| exif_dict = piexif.load(image.info['exif']) | |
| exif_dict.clear() | |
| exif_bytes = piexif.dump(exif_dict) | |
| image_path = 'image_without_exif.jpg' | |
| image.save(image_path, 'jpeg', exif=exif_bytes) | |
| # Read the image file as bytes | |
| with open(image_path, 'rb') as f: | |
| image_bytes = f.read() | |
| # Display the download button | |
| st.download_button( | |
| label="Download Image without EXIF", | |
| data=image_bytes, | |
| file_name='image_without_exif.jpg' | |
| ) | |
| else: | |
| st.write("No EXIF data found.") | |
| else: | |
| st.warning("Please upload a valid photo.") | |
| # Function to convert image to base64 | |
| def image_to_base64(image): | |
| from io import BytesIO | |
| import base64 | |
| img_buffer = BytesIO() | |
| image.save(img_buffer, format='PNG') | |
| img_str = base64.b64encode(img_buffer.getvalue()).decode() | |
| return img_str | |
| if __name__ == '__main__': | |
| main() | |