File size: 1,335 Bytes
f66b5f5
 
 
 
 
48481a1
f66b5f5
 
 
 
 
 
 
48481a1
f66b5f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48481a1
f66b5f5
 
 
 
 
48481a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import cv2
import csv
import json
from deta import Deta
import os
import requests


def preprocess_img(inp_image):
    gray = cv2.cvtColor(inp_image, cv2.COLOR_BGR2GRAY)
    gray_img = cv2.bitwise_not(gray)
    return gray_img


def save_csv(mahalle, il, sokak, apartman):
    adres_full = [mahalle, il, sokak, apartman]

    with open("adress_book.csv", "a", encoding="utf-8") as f:
        write = csv.writer(f)
        write.writerow(adres_full)
    return adres_full


def get_json(mahalle, il, sokak, apartman):
    adres = {"mahalle": mahalle, "il": il, "sokak": sokak, "apartman": apartman}
    dump = json.dumps(adres, indent=4, ensure_ascii=False)
    return dump


def write_db(data_dict):
    # 2) initialize with a project key
    deta_key = os.getenv("DETA_KEY")
    deta = Deta(deta_key)

    # 3) create and use as many DBs as you want!
    users = deta.Base("deprem-ocr")
    users.insert(data_dict)


def ner_response(ocr_input):
    API_URL = "https://api-inference.huggingface.co/models/deprem-ml/deprem-ner"
    headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

    def query(payload):
        response = requests.post(API_URL, headers=headers, json=payload)
        return response.json()

    output = query(
        {
            "inputs": ocr_input,
        }
    )
    return output