Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline | |
| # Load your fine-tuned CamemBERT NER model | |
| model_name = "GEODE/camembert-base-edda-span-classification" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForTokenClassification.from_pretrained(model_name) | |
| ner_pipeline = pipeline("token-classification", model=model, tokenizer=tokenizer, aggregation_strategy="simple") | |
| def extract_coordinates(text): | |
| # Run NER | |
| entities = ner_pipeline(text) | |
| # Collect coordinate entities | |
| coords_text = [ent['word'] for ent in entities if ent['entity_group'] == 'Latlong'] | |
| if coords_text: | |
| return "\n".join(coords_text) | |
| else: | |
| return "No coordinates found" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Geographic Coordinate Extractor (CamemBERT NER Demo)") | |
| with gr.Row(): | |
| inp = gr.Textbox( | |
| label="Enter text", | |
| placeholder="e.g. * 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.", | |
| lines=3 | |
| ) | |
| with gr.Row(): | |
| out_text = gr.Textbox(label="Extracted coordinates") | |
| #out_map = gr.Map(label="Location on Map") | |
| run_btn = gr.Button("Extract & Show") | |
| run_btn.click(fn=extract_coordinates, inputs=inp, outputs=out_text) | |
| # Launch | |
| if __name__ == "__main__": | |
| demo.launch() | |