Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Initialize Hugging Face NER pipeline
|
5 |
+
ner_pipeline = pipeline("ner", model="HooshvareLab/bert-fa-base-uncased", aggregation_strategy="simple")
|
6 |
+
|
7 |
+
def split_name(full_name):
|
8 |
+
entities = ner_pipeline(full_name)
|
9 |
+
prefix = ""
|
10 |
+
first_name = ""
|
11 |
+
last_name = ""
|
12 |
+
for entity in entities:
|
13 |
+
label = entity['entity_group']
|
14 |
+
word = entity['word']
|
15 |
+
if label.lower() == 'prefix':
|
16 |
+
prefix += word + " "
|
17 |
+
elif label.lower() == 'firstname':
|
18 |
+
first_name += word + " "
|
19 |
+
elif label.lower() == 'lastname':
|
20 |
+
last_name += word + " "
|
21 |
+
return prefix.strip(), first_name.strip(), last_name.strip()
|
22 |
+
|
23 |
+
# Gradio interface
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=split_name,
|
26 |
+
inputs=gr.Textbox(label="Full Name (Persian)", placeholder="Enter your full name"),
|
27 |
+
outputs=[
|
28 |
+
gr.Textbox(label="Prefix"),
|
29 |
+
gr.Textbox(label="First Name"),
|
30 |
+
gr.Textbox(label="Last Name"),
|
31 |
+
],
|
32 |
+
)
|
33 |
+
|
34 |
+
demo.launch()
|