Spaces:
Runtime error
Runtime error
Final fix
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import re
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
from transformers import AutoTokenizer
|
@@ -37,13 +38,29 @@ def predict_coordinates(text):
|
|
37 |
outputs = coordinates_model(**encoding)
|
38 |
return round(outputs[0][0][0].item(), 3), round(outputs[0][0][1].item(), 3)
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
def predict(text):
|
41 |
text = process_tweet(text)
|
42 |
relevancy_label, relevancy_score = predict_relevancy(text)
|
43 |
if relevancy_label == 'relevant':
|
44 |
lat, lon = predict_coordinates(text)
|
|
|
45 |
return f"Confident for {round(relevancy_score * 100, 2)}% that tweet has the geolocation relevant information.\n" + \
|
46 |
-
f"Predicted coordinates are: lat: {lat} lon: {lon}"
|
|
|
47 |
return f"Confident for {relevancy_score * 100}% that tweet does not have the geolocation relevant information."
|
48 |
|
49 |
iface = gr.Interface(fn=predict, inputs="text", outputs="text")
|
|
|
1 |
import re
|
2 |
+
import requests
|
3 |
import gradio as gr
|
4 |
from transformers import pipeline
|
5 |
from transformers import AutoTokenizer
|
|
|
38 |
outputs = coordinates_model(**encoding)
|
39 |
return round(outputs[0][0][0].item(), 3), round(outputs[0][0][1].item(), 3)
|
40 |
|
41 |
+
def reverse_geocode(lat, lon):
|
42 |
+
payload = {
|
43 |
+
'lat' : lat,
|
44 |
+
'lon' : lon,
|
45 |
+
'zoom' : 12,
|
46 |
+
'format' : 'jsonv2',
|
47 |
+
'accept-language' : 'en'
|
48 |
+
}
|
49 |
+
try:
|
50 |
+
r = requests.get('https://geocode.maps.co/reverse', params=payload)
|
51 |
+
return f"Reverse geocoded coordinats: {r.json()['display_name']}"
|
52 |
+
except:
|
53 |
+
return "Service couldn't reverse geocode provided coordinates."
|
54 |
+
|
55 |
def predict(text):
|
56 |
text = process_tweet(text)
|
57 |
relevancy_label, relevancy_score = predict_relevancy(text)
|
58 |
if relevancy_label == 'relevant':
|
59 |
lat, lon = predict_coordinates(text)
|
60 |
+
reverse_geocoded = reverse_geocode(lat, lon)
|
61 |
return f"Confident for {round(relevancy_score * 100, 2)}% that tweet has the geolocation relevant information.\n" + \
|
62 |
+
f"Predicted coordinates are: lat: {lat} lon: {lon}.\n" + \
|
63 |
+
f"{reverse_geocoded}"
|
64 |
return f"Confident for {relevancy_score * 100}% that tweet does not have the geolocation relevant information."
|
65 |
|
66 |
iface = gr.Interface(fn=predict, inputs="text", outputs="text")
|