Shahriar-jaman commited on
Commit
81fa4ad
·
verified ·
1 Parent(s): e05f7a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -10,7 +10,7 @@ import gradio as gr
10
  from datetime import datetime
11
  import json
12
  import re
13
- import exifread
14
 
15
  # Initialize FastAPI app with increased upload limit (10MB)
16
  app = FastAPI()
@@ -36,14 +36,14 @@ def resize_image(image: Image.Image, max_size: int = 1024) -> Image.Image:
36
  # Extract EXIF metadata, including GPS and timestamp
37
  def extract_metadata(image_data: bytes) -> dict:
38
  try:
39
- tags = exifread.process_file(io.BytesIO(image_data), details=False)
40
  metadata = {
41
- "timestamp": str(tags.get("EXIF DateTimeOriginal", "N/A")),
42
  "gps": {
43
- "latitude": str(tags.get("GPS GPSLatitude", "N/A")),
44
- "longitude": str(tags.get("GPS GPSLongitude", "N/A"))
45
  },
46
- "camera": str(tags.get("EXIF Make", "N/A")) + " " + str(tags.get("EXIF Model", "N/A"))
47
  }
48
  return metadata
49
  except Exception as e:
 
10
  from datetime import datetime
11
  import json
12
  import re
13
+ from exif import Image as ExifImage
14
 
15
  # Initialize FastAPI app with increased upload limit (10MB)
16
  app = FastAPI()
 
36
  # Extract EXIF metadata, including GPS and timestamp
37
  def extract_metadata(image_data: bytes) -> dict:
38
  try:
39
+ exif_img = ExifImage(io.BytesIO(image_data))
40
  metadata = {
41
+ "timestamp": exif_img.get("datetime_original", "N/A"),
42
  "gps": {
43
+ "latitude": exif_img.get("gps_latitude", "N/A"),
44
+ "longitude": exif_img.get("gps_longitude", "N/A")
45
  },
46
+ "camera": f"{exif_img.get('make', 'N/A')} {exif_img.get('model', 'N/A')}"
47
  }
48
  return metadata
49
  except Exception as e: