SalmanML commited on
Commit
002ac57
1 Parent(s): 74fc7fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -53,6 +53,24 @@ def query(payload):
53
  response = requests.post(API_URL, headers=headers, json=payload)
54
  return response.json()
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  ### DRAWING DETECTION FUNCTION ###
58
  def drawing_detection(image):
@@ -79,28 +97,11 @@ st.title("_Business_ card data extractor using opencv and streamlit :sunglasses:
79
  result,result2=image_upload_and_ocr(reader)
80
  darwing_image=drawing_detection(result2)
81
 
82
-
83
-
84
-
85
  output = query({
86
  "inputs": result,
87
  })
88
 
89
- data = output
90
-
91
- named_entities = {}
92
-
93
- for entity in data:
94
- entity_type = entity['entity_group']
95
- entity_text = entity['word']
96
-
97
- if entity_type not in named_entities:
98
- named_entities[entity_type] = []
99
-
100
- named_entities[entity_type].append(entity_text)
101
-
102
- for entity_type, entities in named_entities.items():
103
- print(f"{entity_type}: {', '.join(entities)}")
104
-
105
-
106
-
 
53
  response = requests.post(API_URL, headers=headers, json=payload)
54
  return response.json()
55
 
56
+ def get_ner_from_transformer(output):
57
+ data = output
58
+ named_entities = {}
59
+ for entity in data:
60
+ entity_type = entity['entity_group']
61
+ entity_text = entity['word']
62
+
63
+ if entity_type not in named_entities:
64
+ named_entities[entity_type] = []
65
+
66
+ named_entities[entity_type].append(entity_text)
67
+
68
+ for entity_type, entities in named_entities.items():
69
+ # print(f"{entity_type}: {', '.join(entities)}")
70
+ return entity_type,named_entities
71
+
72
+
73
+
74
 
75
  ### DRAWING DETECTION FUNCTION ###
76
  def drawing_detection(image):
 
97
  result,result2=image_upload_and_ocr(reader)
98
  darwing_image=drawing_detection(result2)
99
 
100
+
 
 
101
  output = query({
102
  "inputs": result,
103
  })
104
 
105
+ entity_type,named_entities= get_ner_from_transformer(output)
106
+ st.write(entity_type)
107
+ st.write(named_entities)