Spaces:
Runtime error
Runtime error
Add some beauty
Browse files- app.py +26 -11
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import re
|
2 |
import requests
|
3 |
import gradio as gr
|
|
|
4 |
from transformers import pipeline
|
5 |
from transformers import AutoTokenizer
|
6 |
from transformers import AutoModelForSequenceClassification
|
@@ -19,13 +20,13 @@ def process_tweet(tweet):
|
|
19 |
return tweet #if len(tweet) > 0 else ""
|
20 |
|
21 |
tokenizer = AutoTokenizer.from_pretrained(
|
22 |
-
"azamat/
|
23 |
)
|
24 |
|
25 |
-
relevancy_pipeline = pipeline("sentiment-analysis", model="azamat/
|
26 |
|
27 |
coordinates_model = AutoModelForSequenceClassification.from_pretrained(
|
28 |
-
"azamat/
|
29 |
)
|
30 |
|
31 |
def predict_relevancy(text):
|
@@ -48,22 +49,36 @@ def reverse_geocode(lat, lon):
|
|
48 |
}
|
49 |
try:
|
50 |
r = requests.get('https://geocode.maps.co/reverse', params=payload)
|
51 |
-
return f"Reverse geocoded
|
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 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
65 |
|
66 |
-
gr.Markdown("# **<p align='center'>Twitter geocoding with 🤗 Transformers</p>**")
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
|
|
1 |
import re
|
2 |
import requests
|
3 |
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
from transformers import pipeline
|
6 |
from transformers import AutoTokenizer
|
7 |
from transformers import AutoModelForSequenceClassification
|
|
|
20 |
return tweet #if len(tweet) > 0 else ""
|
21 |
|
22 |
tokenizer = AutoTokenizer.from_pretrained(
|
23 |
+
"azamat/geocoder_coordinates_model"
|
24 |
)
|
25 |
|
26 |
+
relevancy_pipeline = pipeline("sentiment-analysis", model="azamat/geocoder_relevancy_model")
|
27 |
|
28 |
coordinates_model = AutoModelForSequenceClassification.from_pretrained(
|
29 |
+
"azamat/geocoder_coordinates_model",
|
30 |
)
|
31 |
|
32 |
def predict_relevancy(text):
|
|
|
49 |
}
|
50 |
try:
|
51 |
r = requests.get('https://geocode.maps.co/reverse', params=payload)
|
52 |
+
return f"Reverse geocoded coordinates: {r.json()['display_name']}"
|
53 |
except:
|
54 |
return "Service couldn't reverse geocode provided coordinates."
|
55 |
|
56 |
def predict(text):
|
57 |
text = process_tweet(text)
|
58 |
+
data = {
|
59 |
+
"relevancy_score" : 0,
|
60 |
+
"lat" : 0,
|
61 |
+
"lon" : 0,
|
62 |
+
"reversed lat/lon" : ""
|
63 |
+
}
|
64 |
relevancy_label, relevancy_score = predict_relevancy(text)
|
65 |
if relevancy_label == 'relevant':
|
66 |
+
data['relevancy_score'] = relevancy_score
|
67 |
+
|
68 |
lat, lon = predict_coordinates(text)
|
69 |
+
data['lat'] = lat
|
70 |
+
data['lon'] = lon
|
71 |
+
|
72 |
reverse_geocoded = reverse_geocode(lat, lon)
|
73 |
+
data['reversed lat/lon'] = reverse_geocoded
|
74 |
+
|
75 |
+
return pd.DataFrame([data])
|
76 |
+
|
77 |
+
with gr.Blocks() as demo:
|
78 |
|
79 |
+
gr.Markdown("# **<p align='center'>Twitter geocoding with 🤗 Transformers</p>**")
|
80 |
+
inp = inp = gr.Textbox(placeholder="Enter the tweet",)
|
81 |
+
inp.submit(predict, inp, "dataframe")
|
82 |
|
83 |
+
if __name__ == "__main__":
|
84 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
torch
|
2 |
transformers
|
3 |
-
datasets
|
|
|
|
1 |
torch
|
2 |
transformers
|
3 |
+
datasets
|
4 |
+
pandas
|