Didier commited on
Commit
2469e02
·
verified ·
1 Parent(s): 4ce0be5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import string
3
  import re
 
4
 
5
  from transformers import pipeline
6
 
@@ -33,7 +34,20 @@ def parse_postal_address_can(text):
33
  text = text.lower()
34
  text = replace_punctuation_with_space(text)
35
  text = replace_multiple_spaces(text)
36
- return token_classifier(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
 
39
  #
@@ -51,14 +65,12 @@ with gr.Blocks() as demo:
51
  label="Canadian postal address",
52
  render=False
53
  )
54
- output_text = gr.Textbox(lines=10, render=False)
55
 
56
  gr.Interface(
57
  fn=parse_postal_address_can,
58
  inputs=[input_text,],
59
- outputs=[output_text,],
60
- allow_flagging="never"
61
- #clear_btn=None
62
  )
63
 
64
  with gr.Accordion("Documentation", open=False):
@@ -74,5 +86,5 @@ with gr.Blocks() as demo:
74
  no training data with "street", "str.", ...
75
  """)
76
 
77
- if __name__ == "__main__":
78
- demo.launch()
 
1
  import gradio as gr
2
  import string
3
  import re
4
+ import pandas as pd
5
 
6
  from transformers import pipeline
7
 
 
34
  text = text.lower()
35
  text = replace_punctuation_with_space(text)
36
  text = replace_multiple_spaces(text)
37
+ results = token_classifier(text)
38
+
39
+ # Format the output as a dataframe
40
+ data = []
41
+ for result in results:
42
+ data.append({
43
+ 'entity_group': result['entity_group'],
44
+ 'score': round(result['score'], ndigits=2),
45
+ 'word': result['word'],
46
+ 'start': result['start'],
47
+ 'end': result['end']
48
+ })
49
+ df = pd.DataFrame(data)
50
+ return df
51
 
52
 
53
  #
 
65
  label="Canadian postal address",
66
  render=False
67
  )
68
+ output = gr.DataFrame(row_count=10, render=False)
69
 
70
  gr.Interface(
71
  fn=parse_postal_address_can,
72
  inputs=[input_text,],
73
+ outputs=[output,]
 
 
74
  )
75
 
76
  with gr.Accordion("Documentation", open=False):
 
86
  no training data with "street", "str.", ...
87
  """)
88
 
89
+
90
+ demo.launch()