WebashalarForML commited on
Commit
8ee9567
·
verified ·
1 Parent(s): c346424

Update backup/backup.py

Browse files
Files changed (1) hide show
  1. backup/backup.py +75 -75
backup/backup.py CHANGED
@@ -1,75 +1,75 @@
1
- from .model import GLiNER
2
-
3
- # Initialize GLiNER with the base model
4
- model = GLiNER.from_pretrained("urchade/gliner_mediumv2.1")
5
-
6
- # Sample text for entity prediction
7
- text = """
8
- lenskart m: (0)9428002330 Lenskart Store,Surat m: (0)9723817060) e:lenskartsurat@gmail.com Store Address UG-4.Ascon City.Opp.Maheshwari Bhavan,Citylight,Surat-395007"""
9
-
10
- # Labels for entity prediction
11
- # # Most GLiNER models should work best when entity types are in lower case or title case
12
- # labels = ["Person", "Mail", "Number", "Address", "Organization","Designation"]
13
-
14
- # # Perform entity prediction
15
- # entities = model.predict_entities(text, labels, threshold=0.5)
16
-
17
-
18
- def NER_Model(text):
19
-
20
- labels = ["Person", "Mail", "Number", "Address", "Organization","Designation","Link"]
21
-
22
- # Perform entity prediction
23
- entities = model.predict_entities(text, labels, threshold=0.5)
24
-
25
- # Initialize the processed data dictionary
26
- processed_data = {
27
- "Name": [],
28
- "Contact": [],
29
- "Designation": [],
30
- "Address": [],
31
- "Link": [],
32
- "Company": [],
33
- "Email": [],
34
- "extracted_text": "",
35
- }
36
-
37
- for entity in entities:
38
-
39
- print(entity["text"], "=>", entity["label"])
40
-
41
- #loading the data into json
42
- if entity["label"]==labels[0]:
43
- processed_data['Name'].extend([entity["text"]])
44
-
45
- if entity["label"]==labels[1]:
46
- processed_data['Email'].extend([entity["text"]])
47
-
48
- if entity["label"]==labels[2]:
49
- processed_data['Contact'].extend([entity["text"]])
50
-
51
- if entity["label"]==labels[3]:
52
- processed_data['Address'].extend([entity["text"]])
53
-
54
- if entity["label"]==labels[4]:
55
- processed_data['Company'].extend([entity["text"]])
56
-
57
- if entity["label"]==labels[5]:
58
- processed_data['Designation'].extend([entity["text"]])
59
-
60
- if entity["label"]==labels[6]:
61
- processed_data['Link'].extend([entity["text"]])
62
-
63
-
64
- processed_data['Address']=[', '.join(processed_data['Address'])]
65
- processed_data['extracted_text']=[text]
66
-
67
- return processed_data
68
-
69
- # result=NER_Model(text)
70
- # print(result)
71
-
72
-
73
-
74
-
75
-
 
1
+ from model import GLiNER
2
+
3
+ # Initialize GLiNER with the base model
4
+ model = GLiNER.from_pretrained("urchade/gliner_mediumv2.1")
5
+
6
+ # Sample text for entity prediction
7
+ text = """
8
+ lenskart m: (0)9428002330 Lenskart Store,Surat m: (0)9723817060) e:lenskartsurat@gmail.com Store Address UG-4.Ascon City.Opp.Maheshwari Bhavan,Citylight,Surat-395007"""
9
+
10
+ # Labels for entity prediction
11
+ # # Most GLiNER models should work best when entity types are in lower case or title case
12
+ # labels = ["Person", "Mail", "Number", "Address", "Organization","Designation"]
13
+
14
+ # # Perform entity prediction
15
+ # entities = model.predict_entities(text, labels, threshold=0.5)
16
+
17
+
18
+ def NER_Model(text):
19
+
20
+ labels = ["Person", "Mail", "Number", "Address", "Organization","Designation","Link"]
21
+
22
+ # Perform entity prediction
23
+ entities = model.predict_entities(text, labels, threshold=0.5)
24
+
25
+ # Initialize the processed data dictionary
26
+ processed_data = {
27
+ "Name": [],
28
+ "Contact": [],
29
+ "Designation": [],
30
+ "Address": [],
31
+ "Link": [],
32
+ "Company": [],
33
+ "Email": [],
34
+ "extracted_text": "",
35
+ }
36
+
37
+ for entity in entities:
38
+
39
+ print(entity["text"], "=>", entity["label"])
40
+
41
+ #loading the data into json
42
+ if entity["label"]==labels[0]:
43
+ processed_data['Name'].extend([entity["text"]])
44
+
45
+ if entity["label"]==labels[1]:
46
+ processed_data['Email'].extend([entity["text"]])
47
+
48
+ if entity["label"]==labels[2]:
49
+ processed_data['Contact'].extend([entity["text"]])
50
+
51
+ if entity["label"]==labels[3]:
52
+ processed_data['Address'].extend([entity["text"]])
53
+
54
+ if entity["label"]==labels[4]:
55
+ processed_data['Company'].extend([entity["text"]])
56
+
57
+ if entity["label"]==labels[5]:
58
+ processed_data['Designation'].extend([entity["text"]])
59
+
60
+ if entity["label"]==labels[6]:
61
+ processed_data['Link'].extend([entity["text"]])
62
+
63
+
64
+ processed_data['Address']=[', '.join(processed_data['Address'])]
65
+ processed_data['extracted_text']=[text]
66
+
67
+ return processed_data
68
+
69
+ # result=NER_Model(text)
70
+ # print(result)
71
+
72
+
73
+
74
+
75
+