import gradio as gr | |
from transformers import pipeline | |
# Specify the name of the model | |
model_name = 'ehri-ner/xlm-roberta-large-ehri-ner-all' | |
# Load the model from Hugging Face | |
ner_model = pipeline('ner', model=model_name) | |
def predict(text): | |
# Use the model to predict the named entities | |
entities = ner_model(text) | |
# Format the output | |
result = {entity['entity']: entity['word'] for entity in entities} | |
return result | |
# Define the Gradio interface | |
iface = gr.Interface(fn=predict, | |
inputs=gr.inputs.Textbox(lines=2, placeholder='Enter text here...'), | |
outputs='json') | |
# Launch the interface | |
iface.launch() |