geolocation87 commited on
Commit
b37455f
·
verified ·
1 Parent(s): d0450df

Create app.py

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