File size: 1,018 Bytes
0d9dfb9
717c137
0d9dfb9
 
 
 
b37455f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import torch
from geoclip import GeoCLIP
if torch.cuda.is_available():
  model = GeoCLIP().to("cuda")
else:
  model = GeoCLIP()
print("loaded")
from PIL import Image
import tempfile
from pathlib import Path
import gradio as gr
def predict(image):
    with tempfile.TemporaryDirectory() as tmp_dir:
        tmppath = Path(tmp_dir) / "tmp.jpg"
        image.save(str(tmppath))
        top_pred_gps, top_pred_prob = model.predict(str(tmppath), top_k=50)
        
    predictions = []
    for i in range(5):
        lat, lon = top_pred_gps[i]
        probpercent = top_pred_prob[i] * 100
        prediction = f"{i+1}: ({lat:.6f}, {lon:.6f}) - probability: {probpercent:.2f}%"
        predictions.append(prediction)
    return "\n".join(predictions)
app = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil", label="upload iamge"),
    outputs=gr.Textbox(label="predictions"),
    title="web interface for geolocation project @inputoutputcontrol",
    description="upload image to predict location",
)
app.launch()