Spaces:
Sleeping
Sleeping
Ludovic Moncla
commited on
Commit
·
4a51b31
1
Parent(s):
7cb1dfd
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import re
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 4 |
|
|
@@ -17,18 +16,10 @@ def extract_coordinates(text):
|
|
| 17 |
# Collect coordinate entities
|
| 18 |
coords_text = [ent['word'] for ent in entities if ent['entity_group'] == 'Latlong']
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
lat_match, lon_match = matches[0], matches[1]
|
| 25 |
-
lat = dms_to_dd(*lat_match)
|
| 26 |
-
lon = dms_to_dd(*lon_match)
|
| 27 |
-
parsed_coords.append([lat, lon])
|
| 28 |
-
|
| 29 |
-
result_text = "\n".join(coords_text) if coords_text else "No coordinates found"
|
| 30 |
-
return result_text, parsed_coords if parsed_coords else None
|
| 31 |
-
|
| 32 |
|
| 33 |
|
| 34 |
def norm_coordinates(text):
|
|
@@ -42,19 +33,7 @@ def norm_coordinates(text):
|
|
| 42 |
predicted_coordinates_from_pipeline = generator(input_text, max_length=128)
|
| 43 |
|
| 44 |
return predicted_coordinates_from_pipeline[0]['generated_text']
|
| 45 |
-
|
| 46 |
-
# Function to convert DMS to decimal
|
| 47 |
-
def dms_to_dd(degrees, minutes, seconds, direction):
|
| 48 |
-
dd = float(degrees) + float(minutes)/60 + float(seconds)/3600
|
| 49 |
-
if direction in ["S", "W"]:
|
| 50 |
-
dd *= -1
|
| 51 |
-
return dd
|
| 52 |
-
|
| 53 |
-
# Regex for DMS coordinates (example: 48°51′29.9″N or 2°17′40.2″E)
|
| 54 |
-
dms_pattern = re.compile(
|
| 55 |
-
r"(\d{1,3})[°\s]\s*(\d{1,2})[′']\s*(\d{1,2}(?:\.\d+)?)[″\"]?\s*([NSEW])"
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
|
| 59 |
examples = [
|
| 60 |
"* AACH ou ACH, s. f. petite ville d'Allemagne dans le cercle de Souabe, près de la source de l'Aach. Long. 26. 57. lat. 47. 55.",
|
|
@@ -85,9 +64,7 @@ with gr.Blocks() as demo:
|
|
| 85 |
run_btn.click(fn=extract_coordinates, inputs=inp, outputs=out_text)
|
| 86 |
|
| 87 |
out_text = gr.Textbox(label="Extracted and normalized DMS coordinates (fine-tuned mT5)")
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
run_btn.click(fn=norm_coordinates, inputs=inp, outputs=[out_text, out_map])
|
| 91 |
|
| 92 |
with gr.Row():
|
| 93 |
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 3 |
|
|
|
|
| 16 |
# Collect coordinate entities
|
| 17 |
coords_text = [ent['word'] for ent in entities if ent['entity_group'] == 'Latlong']
|
| 18 |
|
| 19 |
+
if coords_text:
|
| 20 |
+
return "\n".join(coords_text)
|
| 21 |
+
else:
|
| 22 |
+
return "No coordinates found"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def norm_coordinates(text):
|
|
|
|
| 33 |
predicted_coordinates_from_pipeline = generator(input_text, max_length=128)
|
| 34 |
|
| 35 |
return predicted_coordinates_from_pipeline[0]['generated_text']
|
| 36 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
examples = [
|
| 39 |
"* AACH ou ACH, s. f. petite ville d'Allemagne dans le cercle de Souabe, près de la source de l'Aach. Long. 26. 57. lat. 47. 55.",
|
|
|
|
| 64 |
run_btn.click(fn=extract_coordinates, inputs=inp, outputs=out_text)
|
| 65 |
|
| 66 |
out_text = gr.Textbox(label="Extracted and normalized DMS coordinates (fine-tuned mT5)")
|
| 67 |
+
run_btn.click(fn=norm_coordinates, inputs=inp, outputs=out_text)
|
|
|
|
|
|
|
| 68 |
|
| 69 |
with gr.Row():
|
| 70 |
|