SalmanML commited on
Commit
74fc7fc
·
verified ·
1 Parent(s): b035e2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -28,6 +28,13 @@ import cv2
28
  import requests
29
  import re
30
  from PIL import Image
 
 
 
 
 
 
 
31
 
32
  ## Image uploading function ##
33
  def image_upload_and_ocr(reader):
@@ -42,6 +49,10 @@ def image_upload_and_ocr(reader):
42
  return result,result2
43
 
44
 
 
 
 
 
45
 
46
  ### DRAWING DETECTION FUNCTION ###
47
  def drawing_detection(image):
@@ -71,4 +82,25 @@ darwing_image=drawing_detection(result2)
71
 
72
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
 
28
  import requests
29
  import re
30
  from PIL import Image
31
+ import streamlit as st
32
+ import os
33
+
34
+ key=os.environ.getattribute("api_key")
35
+ print(key)
36
+ API_URL = "https://api-inference.huggingface.co/models/flair/ner-english-large"
37
+ headers = {"Authorization": "Bearer {key}"}
38
 
39
  ## Image uploading function ##
40
  def image_upload_and_ocr(reader):
 
49
  return result,result2
50
 
51
 
52
+ 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):
 
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