Spaces:
Runtime error
Runtime error
Download utils.py from deprem-ml/deprem-ocr: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/deprem-ml/deprem-ocr/resolve/main/utils.py
- Command line
-
hf download hf://spaces/deprem-ml/deprem-ocr/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/deprem-ml/deprem-ocr/resolve/main/utils.py
1.34 kB
| 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 = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fdeprem-ml%2Fdeprem-ner%26quot%3B%3C%2Fspan%3E%3C!----%3E%3C%2Ftd%3E%3C%2Ftr%3E%3Ctr id="L42"> | 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 | |||