Spaces:
Runtime error
Runtime error
import gradio as gr | |
import torch | |
from geoclip import GeoCLIP | |
# Load the GeoCLIP model | |
model = GeoCLIP() | |
# Define the function for geolocation prediction | |
def predict_location(image_path): | |
top_pred_gps, top_pred_prob = model.predict(image_path, top_k=5) | |
results = [] | |
for i in range(5): | |
lat, lon = top_pred_gps[i] | |
prob = top_pred_prob[i] | |
results.append(f"Prediction {i+1}: ({lat:.6f}, {lon:.6f}) | Probability: {prob:.6f}") | |
return "\n".join(results) | |
# Define Gradio interface | |
interface = gr.Interface( | |
fn=predict_location, | |
inputs=gr.Image(type="filepath", label="Upload Image"), | |
outputs=gr.Textbox(label="Predicted Locations"), | |
title="GeoCLIP Geolocation", | |
description="Upload an image, and GeoCLIP will predict the top 5 GPS locations." | |
) | |
# Launch the Gradio app | |
if __name__ == "__main__": | |
interface.launch() | |