Spaces:
Runtime error
Runtime error
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 | |