Spaces:
Sleeping
Sleeping
Ludovic Moncla
commited on
Commit
·
4d536cc
1
Parent(s):
740da73
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
| 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 detect_coordinates(text):
|
| 11 |
# Run binary classification
|
| 12 |
result = binary_classifier(text)
|
|
@@ -33,15 +40,20 @@ def extract_coordinates(text):
|
|
| 33 |
# bert-base-multilingual-cased-binary-classifier-edda-coords
|
| 34 |
|
| 35 |
def norm_coordinates(text):
|
|
|
|
| 36 |
if detect_coordinates(text) == "No coordinates found":
|
| 37 |
-
|
| 38 |
# Example input text
|
| 39 |
input_text = "extract_coordinates: " + text
|
| 40 |
|
| 41 |
# Generate prediction using the pipeline
|
| 42 |
predicted_coordinates_from_pipeline = generator(input_text, max_length=128)
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
examples = [
|
|
|
|
| 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)
|
| 13 |
+
return [point[0], point[1]-17.66]
|
| 14 |
+
except:
|
| 15 |
+
return None
|
| 16 |
+
|
| 17 |
def detect_coordinates(text):
|
| 18 |
# Run binary classification
|
| 19 |
result = binary_classifier(text)
|
|
|
|
| 40 |
# bert-base-multilingual-cased-binary-classifier-edda-coords
|
| 41 |
|
| 42 |
def norm_coordinates(text):
|
| 43 |
+
result_text = ""
|
| 44 |
if detect_coordinates(text) == "No coordinates found":
|
| 45 |
+
result_text = "No coordinates found"
|
| 46 |
# Example input text
|
| 47 |
input_text = "extract_coordinates: " + text
|
| 48 |
|
| 49 |
# Generate prediction using the pipeline
|
| 50 |
predicted_coordinates_from_pipeline = generator(input_text, max_length=128)
|
| 51 |
|
| 52 |
+
result_text = predicted_coordinates_from_pipeline[0]['generated_text']
|
| 53 |
+
|
| 54 |
+
coords = dms_to_dd(result_text)
|
| 55 |
+
|
| 56 |
+
return result_text, coords
|
| 57 |
|
| 58 |
|
| 59 |
examples = [
|