import numpy as np import pandas as pd import matplotlib.pylab as plt import PIL.Image as Image import tensorflow as tf import tensorflow_hub as hub import gradio as gr from einops import rearrange import s2cell from geopy.geocoders import Nominatim TF_MODEL_URL = 'https://tfhub.dev/google/planet/vision/classifier/planet_v2/1' IMAGE_SHAPE = (299, 299) labels=pd.read_csv('planet_v2_labelmap.csv') classifier = tf.keras.Sequential([hub.KerasLayer(TF_MODEL_URL, input_shape=IMAGE_SHAPE+(3,) )]) def classify_image(image): img = image/255.0 img = rearrange(img, 'h w c -> 1 h w c') prediction = classifier.predict(img) s2code = np.argmax(prediction) loc=labels['S2CellId'][s2code] location=s2cell.token_to_lat_lon(loc) geolocator = Nominatim(user_agent="coordinateconverter") address = location location_add = geolocator.reverse(address) return location,location_add title = 'Photo Geolocation' description = 'Just upload or drop an image to know where your photo is taken . ' article ='''PlaNet -Photo Geolocation with Convolutional Neural Networks. A gradio demo app for estimation of the address and coordinates of your photo.