rmayormartins
commited on
Commit
·
a97deb9
1
Parent(s):
81dc990
Subindo arquivos
Browse files- README.md +17 -7
- app.py +166 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,13 +1,23 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: ecl-2.0
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: image-inspector
|
3 |
+
emoji: 🔍
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: green
|
6 |
sdk: gradio
|
7 |
+
sdk_version: "4.12.0"
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
+
# Inspetor de Imagem 🔍
|
13 |
+
|
14 |
+
O Inspetor de Imagem é uma ferramenta que permite a você fazer o upload de uma imagem (.jpg, .png, .bmp, etc.) e exibir detalhes sobre ela, como formato, dimensões, profundidade de cor, DPI, tamanho do arquivo, timestamp de modificação e tipo de compressão.
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
## Versão Teste 1 (25/04)
|
19 |
+
|
20 |
+
- Desenvolvedor: Ramon Mayor Martins
|
21 |
+
- Para sugestões ou relatórios de bugs, por favor, entre em contato pelo e-mail: [[email protected]](mailto:[email protected])
|
22 |
+
|
23 |
+
|
app.py
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import glob
|
4 |
+
import exifread
|
5 |
+
from iptcinfo3 import IPTCInfo
|
6 |
+
from google.colab import drive
|
7 |
+
|
8 |
+
# Function to mount Google Drive (for testing purposes)
|
9 |
+
def mount_drive():
|
10 |
+
drive.mount('/content/drive')
|
11 |
+
|
12 |
+
# Extract EXIF metadata
|
13 |
+
def extract_exif_metadata(filename):
|
14 |
+
with open(filename, 'rb') as img_file:
|
15 |
+
tags = exifread.process_file(img_file, stop_tag="EXIF UserComment")
|
16 |
+
exif_data = {}
|
17 |
+
for tag in tags.keys():
|
18 |
+
exif_data[tag] = str(tags[tag])
|
19 |
+
return exif_data
|
20 |
+
|
21 |
+
# Extract IPTC metadata
|
22 |
+
def extract_iptc_metadata(filename):
|
23 |
+
try:
|
24 |
+
info = IPTCInfo(filename, force=True)
|
25 |
+
return info.data
|
26 |
+
except Exception as e:
|
27 |
+
return {}
|
28 |
+
|
29 |
+
# Perform alternative license searches
|
30 |
+
def alternative_license_search(exif_data, iptc_data):
|
31 |
+
possible_license_keywords = ['license', 'rights', 'usage rights', 'legal', 'copyright', 'cc']
|
32 |
+
possible_license = None
|
33 |
+
|
34 |
+
for tag, value in exif_data.items():
|
35 |
+
for keyword in possible_license_keywords:
|
36 |
+
if keyword in tag.lower() or keyword in str(value).lower():
|
37 |
+
possible_license = value
|
38 |
+
break
|
39 |
+
if possible_license:
|
40 |
+
break
|
41 |
+
|
42 |
+
if not possible_license:
|
43 |
+
for tag, value in iptc_data.items():
|
44 |
+
for keyword in possible_license_keywords:
|
45 |
+
if keyword in str(tag).lower() or keyword in str(value).lower():
|
46 |
+
possible_license = value
|
47 |
+
break
|
48 |
+
if possible_license:
|
49 |
+
break
|
50 |
+
|
51 |
+
return possible_license
|
52 |
+
|
53 |
+
# Check for different types of licenses
|
54 |
+
def check_license(exif_data, iptc_data):
|
55 |
+
license_type = None
|
56 |
+
|
57 |
+
if 'EXIF UserComment' in exif_data:
|
58 |
+
comment = exif_data['EXIF UserComment'].lower()
|
59 |
+
if 'creativecommons' in comment:
|
60 |
+
license_type = 'Creative Commons'
|
61 |
+
elif 'public domain' in comment:
|
62 |
+
license_type = 'Public Domain'
|
63 |
+
elif 'royalty-free' in comment:
|
64 |
+
license_type = 'Royalty-Free'
|
65 |
+
|
66 |
+
if not license_type and 'copyright' in iptc_data:
|
67 |
+
copyright_info = str(iptc_data['copyright']).lower()
|
68 |
+
if 'creativecommons' in copyright_info:
|
69 |
+
license_type = 'Creative Commons'
|
70 |
+
elif 'public domain' in copyright_info:
|
71 |
+
license_type = 'Public Domain'
|
72 |
+
elif 'royalty-free' in copyright_info:
|
73 |
+
license_type = 'Royalty-Free'
|
74 |
+
elif 'all rights reserved' in copyright_info:
|
75 |
+
license_type = 'All Rights Reserved'
|
76 |
+
|
77 |
+
return license_type
|
78 |
+
|
79 |
+
# Main function to process uploaded images
|
80 |
+
def process_images(files=None, url=None, drive_path=None):
|
81 |
+
results = []
|
82 |
+
license_summary = {
|
83 |
+
'No License Found': 0,
|
84 |
+
'Creative Commons': 0,
|
85 |
+
'Public Domain': 0,
|
86 |
+
'Royalty-Free': 0,
|
87 |
+
'All Rights Reserved': 0,
|
88 |
+
'Possible License Found (Alternative)': 0
|
89 |
+
}
|
90 |
+
|
91 |
+
if files:
|
92 |
+
for file in files:
|
93 |
+
filename = file.name
|
94 |
+
file_path = os.path.join("/tmp", filename)
|
95 |
+
|
96 |
+
if hasattr(file, 'read'):
|
97 |
+
with open(file_path, "wb") as f:
|
98 |
+
f.write(file.read())
|
99 |
+
else:
|
100 |
+
with open(file_path, "wb") as f:
|
101 |
+
f.write(file.encode('utf-8'))
|
102 |
+
|
103 |
+
exif_data = extract_exif_metadata(file_path)
|
104 |
+
iptc_data = extract_iptc_metadata(file_path)
|
105 |
+
license_type = check_license(exif_data, iptc_data)
|
106 |
+
|
107 |
+
if not license_type:
|
108 |
+
possible_license = alternative_license_search(exif_data, iptc_data)
|
109 |
+
if possible_license:
|
110 |
+
license_type = 'Possible License Found (Alternative)'
|
111 |
+
|
112 |
+
if license_type:
|
113 |
+
license_summary[license_type] += 1
|
114 |
+
else:
|
115 |
+
license_summary['No License Found'] += 1
|
116 |
+
|
117 |
+
results.append(f"File: {filename} - License: {license_type if license_type else 'No License Found'}")
|
118 |
+
|
119 |
+
if url:
|
120 |
+
results.append("URL analysis not implemented yet")
|
121 |
+
|
122 |
+
if drive_path:
|
123 |
+
for filename in glob.iglob(drive_path + '/*', recursive=True):
|
124 |
+
if filename.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff')):
|
125 |
+
exif_data = extract_exif_metadata(filename)
|
126 |
+
iptc_data = extract_iptc_metadata(filename)
|
127 |
+
license_type = check_license(exif_data, iptc_data)
|
128 |
+
|
129 |
+
if not license_type:
|
130 |
+
possible_license = alternative_license_search(exif_data, iptc_data)
|
131 |
+
if possible_license:
|
132 |
+
license_type = 'Possible License Found (Alternative)'
|
133 |
+
|
134 |
+
if license_type:
|
135 |
+
license_summary[license_type] += 1
|
136 |
+
else:
|
137 |
+
license_summary['No License Found'] += 1
|
138 |
+
|
139 |
+
results.append(f"File: {filename} - License: {license_type if license_type else 'No License Found'}")
|
140 |
+
|
141 |
+
summary = "\nLicense Summary:\n"
|
142 |
+
for license_type, count in license_summary.items():
|
143 |
+
summary += f"{license_type}: {count} images\n"
|
144 |
+
|
145 |
+
return "\n".join(results) + summary
|
146 |
+
|
147 |
+
# Gradio interface
|
148 |
+
with gr.Blocks() as interface:
|
149 |
+
gr.Markdown("# Image License Inspector 🔍")
|
150 |
+
gr.Markdown("## The Image License Inspector allows you to upload images and inspect their metadata for potential licenses such as Creative Commons, Public Domain, and others.")
|
151 |
+
gr.Markdown("### Version 1 developed by Ramon Mayor Martins, 2024 | [Personal Website](https://rmayormartins.github.io/) | [Hugging Face Spaces](https://huggingface.co/rmayormartins)")
|
152 |
+
|
153 |
+
with gr.Row():
|
154 |
+
with gr.Column():
|
155 |
+
files = gr.File(file_count="multiple", label="Upload Images")
|
156 |
+
url = gr.Textbox(label="Or provide an image URL")
|
157 |
+
drive_path = gr.Textbox(label="Or provide a Google Drive folder path (e.g., /content/drive/MyDrive/yourfolder)")
|
158 |
+
|
159 |
+
output = gr.Textbox(label="Results")
|
160 |
+
|
161 |
+
submit_button = gr.Button("Inspect")
|
162 |
+
submit_button.click(process_images, inputs=[files, url, drive_path], outputs=output)
|
163 |
+
|
164 |
+
mount_drive()
|
165 |
+
|
166 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
exifread
|
3 |
+
iptcinfo3
|
4 |
+
|