Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 3 |
-
|
| 4 |
-
# Load the model
|
| 5 |
-
model_name = "tahirmuhammadcs/multi-ner-final"
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
-
model = AutoModelForTokenClassification.from_pretrained(model_name)
|
| 8 |
-
|
| 9 |
-
ner = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
|
| 10 |
-
|
| 11 |
-
# Define prediction function
|
| 12 |
-
def predict(text):
|
| 13 |
-
result = ner(text)
|
| 14 |
-
return result
|
| 15 |
-
|
| 16 |
-
# Interface (you can hide this by setting `live=False`)
|
| 17 |
-
demo = gr.Interface(
|
| 18 |
-
fn=predict,
|
| 19 |
-
inputs=gr.Textbox(lines=4, placeholder="Enter text here..."),
|
| 20 |
-
outputs="json",
|
| 21 |
-
title="Multi-language NER",
|
| 22 |
-
description="Named Entity Recognition using Hugging Face Transformers."
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
# Launch the app
|
| 26 |
-
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 3 |
+
|
| 4 |
+
# Load the model
|
| 5 |
+
model_name = "tahirmuhammadcs/multi-ner-final"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
ner = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
|
| 10 |
+
|
| 11 |
+
# Define prediction function
|
| 12 |
+
def predict(text):
|
| 13 |
+
result = ner(text)
|
| 14 |
+
return result
|
| 15 |
+
|
| 16 |
+
# Interface (you can hide this by setting `live=False`)
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=predict,
|
| 19 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter text here..."),
|
| 20 |
+
outputs="json",
|
| 21 |
+
title="Multi-language NER",
|
| 22 |
+
description="Named Entity Recognition using Hugging Face Transformers."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Launch the app
|
| 26 |
+
demo.launch(share=True)
|