alyxx commited on
Commit
cb77f6c
·
1 Parent(s): 7937069

update app.py and requirements

Browse files
Files changed (2) hide show
  1. app.py +16 -21
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,24 +1,19 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
 
 
 
 
 
 
4
 
5
-
6
- ner = pipeline("ner",
7
- model='kaiku03/bert-base-NER-finetuned_custom_complain_dataset_NER9',
8
- # grouped_entities=True,
9
- aggregation_strategy="simple"
10
- )
11
-
12
-
13
- # function for the gradio app
14
  def fn_ner(prompt):
15
  entities = ner(prompt)
16
- # Extract recognized entities and concatenate them into a single string
17
- entity_string = ", ".join([entity['entity'] for entity in entities])
18
- return entity_string
19
-
20
 
21
- # gradio app
22
  # Define example inputs and outputs
23
  examples = [
24
  "Subject: Defective Date: 08-13-2023 Product: XXX speaker Location: 456 Sound Avenue, Audiotown",
@@ -26,16 +21,16 @@ examples = [
26
  "Subject: Missing Parts Date: 08-10-2023 Product: XXX Furniture Set Location: 1800 Antipolo Rizal Furnitown",
27
  ]
28
 
 
29
  iface = gr.Interface(
30
  fn=fn_ner,
31
  inputs='text',
32
- outputs=gr.Label(label="Name Entity Recognition"),
33
- examples=[
34
- [ex] for ex in examples
35
- ],
36
- title='English to Tagalog translator',
37
- description='This demo performs language translation from English to Tagalog.',
38
- article='All done by Kaiku',
39
  )
40
 
 
41
  iface.launch()
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
+ # Load the NER pipeline
5
+ ner = pipeline(
6
+ "ner",
7
+ model='kaiku03/bert-base-NER-finetuned_custom_complain_dataset_NER9',
8
+ aggregation_strategy="simple"
9
+ )
10
 
11
+ # Function for the Gradio app
 
 
 
 
 
 
 
 
12
  def fn_ner(prompt):
13
  entities = ner(prompt)
14
+ entity_info = "\n".join([f"{entity['entity_group']}: {entity['word']}" for entity in entities])
15
+ return entity_info
 
 
16
 
 
17
  # Define example inputs and outputs
18
  examples = [
19
  "Subject: Defective Date: 08-13-2023 Product: XXX speaker Location: 456 Sound Avenue, Audiotown",
 
21
  "Subject: Missing Parts Date: 08-10-2023 Product: XXX Furniture Set Location: 1800 Antipolo Rizal Furnitown",
22
  ]
23
 
24
+ # Create Gradio interface
25
  iface = gr.Interface(
26
  fn=fn_ner,
27
  inputs='text',
28
+ outputs='text',
29
+ examples=[[ex] for ex in examples],
30
+ title='Named Entity Recognition',
31
+ description='This demo performs named entity recognition (NER) on the input text.',
32
+ article='All done by Kaiku'
 
 
33
  )
34
 
35
+ # Launch the interface
36
  iface.launch()
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
  transformers
2
- gradio==3.40
3
  torch
4
  seqeval
5
  evaluate
 
1
  transformers
2
+ gradio==3.14
3
  torch
4
  seqeval
5
  evaluate