Spaces:
Runtime error
Runtime error
Commit
·
48481a1
1
Parent(s):
c7c6e78
moved nerf function to utils
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ def get_text(input_img):
|
|
| 20 |
# Submit button
|
| 21 |
def get_parsed_address(input_img):
|
| 22 |
|
| 23 |
-
address_full_text = get_text(input_img)
|
| 24 |
return openai_response(address_full_text)
|
| 25 |
|
| 26 |
|
|
@@ -76,18 +76,6 @@ def openai_response(ocr_input):
|
|
| 76 |
resp[key] = ""
|
| 77 |
return resp
|
| 78 |
|
| 79 |
-
def ner_response(ocr_input):
|
| 80 |
-
API_URL = "https://api-inference.huggingface.co/models/deprem-ml/deprem-ner"
|
| 81 |
-
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 82 |
-
|
| 83 |
-
def query(payload):
|
| 84 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
| 85 |
-
return response.json()
|
| 86 |
-
|
| 87 |
-
output = query({
|
| 88 |
-
"inputs": ocr_input,
|
| 89 |
-
})
|
| 90 |
-
return output
|
| 91 |
|
| 92 |
# User Interface
|
| 93 |
with gr.Blocks() as demo:
|
|
|
|
| 20 |
# Submit button
|
| 21 |
def get_parsed_address(input_img):
|
| 22 |
|
| 23 |
+
address_full_text = utils.get_text(input_img)
|
| 24 |
return openai_response(address_full_text)
|
| 25 |
|
| 26 |
|
|
|
|
| 76 |
resp[key] = ""
|
| 77 |
return resp
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
# User Interface
|
| 81 |
with gr.Blocks() as demo:
|
utils.py
CHANGED
|
@@ -3,6 +3,7 @@ import csv
|
|
| 3 |
import json
|
| 4 |
from deta import Deta
|
| 5 |
import os
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def preprocess_img(inp_image):
|
|
@@ -10,6 +11,7 @@ def preprocess_img(inp_image):
|
|
| 10 |
gray_img = cv2.bitwise_not(gray)
|
| 11 |
return gray_img
|
| 12 |
|
|
|
|
| 13 |
def save_csv(mahalle, il, sokak, apartman):
|
| 14 |
adres_full = [mahalle, il, sokak, apartman]
|
| 15 |
|
|
@@ -27,9 +29,25 @@ def get_json(mahalle, il, sokak, apartman):
|
|
| 27 |
|
| 28 |
def write_db(data_dict):
|
| 29 |
# 2) initialize with a project key
|
| 30 |
-
deta_key = os.getenv(
|
| 31 |
deta = Deta(deta_key)
|
| 32 |
|
| 33 |
# 3) create and use as many DBs as you want!
|
| 34 |
users = deta.Base("deprem-ocr")
|
| 35 |
users.insert(data_dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import json
|
| 4 |
from deta import Deta
|
| 5 |
import os
|
| 6 |
+
import requests
|
| 7 |
|
| 8 |
|
| 9 |
def preprocess_img(inp_image):
|
|
|
|
| 11 |
gray_img = cv2.bitwise_not(gray)
|
| 12 |
return gray_img
|
| 13 |
|
| 14 |
+
|
| 15 |
def save_csv(mahalle, il, sokak, apartman):
|
| 16 |
adres_full = [mahalle, il, sokak, apartman]
|
| 17 |
|
|
|
|
| 29 |
|
| 30 |
def write_db(data_dict):
|
| 31 |
# 2) initialize with a project key
|
| 32 |
+
deta_key = os.getenv("DETA_KEY")
|
| 33 |
deta = Deta(deta_key)
|
| 34 |
|
| 35 |
# 3) create and use as many DBs as you want!
|
| 36 |
users = deta.Base("deprem-ocr")
|
| 37 |
users.insert(data_dict)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def ner_response(ocr_input):
|
| 41 |
+
API_URL = "https://api-inference.huggingface.co/models/deprem-ml/deprem-ner"
|
| 42 |
+
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 43 |
+
|
| 44 |
+
def query(payload):
|
| 45 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 46 |
+
return response.json()
|
| 47 |
+
|
| 48 |
+
output = query(
|
| 49 |
+
{
|
| 50 |
+
"inputs": ocr_input,
|
| 51 |
+
}
|
| 52 |
+
)
|
| 53 |
+
return output
|