Spaces:
Sleeping
Sleeping
Ludovic Moncla
commited on
Commit
·
a4a96a1
1
Parent(s):
09ff6ee
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,43 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
import geopy
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
binary_classifier = pipeline("text-classification", model="GEODE/bert-base-multilingual-cased-binary-classifier-edda-coords")
|
| 7 |
ner_pipeline = pipeline("token-classification", model="GEODE/camembert-base-edda-span-classification", aggregation_strategy="simple")
|
| 8 |
generator = pipeline("text2text-generation", model="GEODE/mt5-small-coords-norm")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def dms_to_dd(dms):
|
| 11 |
try:
|
| 12 |
point = geopy.Point(dms)
|
|
@@ -53,7 +84,7 @@ def norm_coordinates(text):
|
|
| 53 |
|
| 54 |
coords = dms_to_dd(result_text)
|
| 55 |
|
| 56 |
-
return result_text, coords
|
| 57 |
|
| 58 |
|
| 59 |
examples = [
|
|
@@ -88,8 +119,9 @@ with gr.Blocks() as demo:
|
|
| 88 |
run_btn.click(fn=extract_coordinates, inputs=inp, outputs=out_text)
|
| 89 |
|
| 90 |
out_text = gr.Textbox(label="Extract and normalize DMS coordinates (fine-tuned mT5)")
|
| 91 |
-
out_map = gr.Map(label="Coordinates on Map")
|
| 92 |
-
|
|
|
|
| 93 |
|
| 94 |
with gr.Row():
|
| 95 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
import geopy
|
| 4 |
+
import plotly.graph_objects as go
|
| 5 |
|
| 6 |
|
| 7 |
binary_classifier = pipeline("text-classification", model="GEODE/bert-base-multilingual-cased-binary-classifier-edda-coords")
|
| 8 |
ner_pipeline = pipeline("token-classification", model="GEODE/camembert-base-edda-span-classification", aggregation_strategy="simple")
|
| 9 |
generator = pipeline("text2text-generation", model="GEODE/mt5-small-coords-norm")
|
| 10 |
|
| 11 |
+
|
| 12 |
+
def create_map(lat, long):
|
| 13 |
+
fig = go.Figure(go.Scattermapbox(
|
| 14 |
+
#customdata=text_list,
|
| 15 |
+
lat=[lat],
|
| 16 |
+
lon=[long],
|
| 17 |
+
mode='markers',
|
| 18 |
+
marker=go.scattermapbox.Marker(
|
| 19 |
+
size=6
|
| 20 |
+
),
|
| 21 |
+
#hoverinfo="text",
|
| 22 |
+
#hovertemplate='<b>Name</b>: %{customdata[0]}<br><b>Price</b>: $%{customdata[1]}'
|
| 23 |
+
))
|
| 24 |
+
|
| 25 |
+
fig.update_layout(
|
| 26 |
+
mapbox_style="open-street-map",
|
| 27 |
+
hovermode='closest',
|
| 28 |
+
mapbox=dict(
|
| 29 |
+
bearing=0,
|
| 30 |
+
center=go.layout.mapbox.Center(
|
| 31 |
+
lat=lat,
|
| 32 |
+
lon=long
|
| 33 |
+
),
|
| 34 |
+
pitch=0,
|
| 35 |
+
zoom=9
|
| 36 |
+
),
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
return fig
|
| 40 |
+
|
| 41 |
def dms_to_dd(dms):
|
| 42 |
try:
|
| 43 |
point = geopy.Point(dms)
|
|
|
|
| 84 |
|
| 85 |
coords = dms_to_dd(result_text)
|
| 86 |
|
| 87 |
+
return result_text, create_map(coords[0], coords[1]) if coords else None
|
| 88 |
|
| 89 |
|
| 90 |
examples = [
|
|
|
|
| 119 |
run_btn.click(fn=extract_coordinates, inputs=inp, outputs=out_text)
|
| 120 |
|
| 121 |
out_text = gr.Textbox(label="Extract and normalize DMS coordinates (fine-tuned mT5)")
|
| 122 |
+
#out_map = gr.Map(label="Coordinates on Map")
|
| 123 |
+
map = gr.Plot(label="Coordinates on Map")
|
| 124 |
+
run_btn.click(fn=norm_coordinates, inputs=inp, outputs=[out_text, map])
|
| 125 |
|
| 126 |
with gr.Row():
|
| 127 |
|