-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from CAUSOLDOUTMEN/feat/32-clova-ocr
feat: clova ocr로 변경 (#32)
- Loading branch information
Showing
10 changed files
with
151 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
*.env | ||
*.jpeg | ||
*.png | ||
clova.conf.dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[clova_credentials] | ||
API_URL = ${API_URL} | ||
SECERT_KEY = ${SECERT_KEY} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- manifest.yaml | ||
images: | ||
- name: synoti21/diareat-ocr | ||
newName: synoti21/diareat-ocr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: diareat-ocr | ||
namespace: diareat | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: diareat-ocr | ||
template: | ||
metadata: | ||
labels: | ||
app: diareat-ocr | ||
spec: | ||
revisionHistoryLimit: 3 | ||
containers: | ||
- name: diareat-ocr | ||
image: synoti21/diareat-ocr:latest | ||
imagePullPolicy: Always | ||
resources: | ||
requests: | ||
memory: "512Mi" | ||
cpu: "0.2" | ||
limits: | ||
memory: "1Gi" | ||
cpu: "0.8" | ||
envFrom: | ||
secretRef: | ||
name: diareat-ocr-secret | ||
ports: | ||
- containerPort: 8000 | ||
readinessProbe: | ||
httpGet: | ||
path: /docs | ||
port: 8000 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 5 | ||
failureThreshold: 6 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: diareat-ocr | ||
namespace: diareat | ||
spec: | ||
selector: | ||
app: diareat-ocr | ||
ports: | ||
- port: 8800 | ||
targetPort: 8000 | ||
--- | ||
apiVersion: traefik.containo.us/v1alpha1 | ||
kind: IngressRoute | ||
metadata: | ||
name: diareatocr-route | ||
namespace: diareat | ||
spec: | ||
entryPoints: | ||
- websecure | ||
routes: | ||
- match: Host(`diareat-ocr.thisiswandol.com`) | ||
kind: Rule | ||
services: | ||
- name: diareat-svc | ||
port: 8800 | ||
tls: | ||
certResolver: myresolver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+88 Bytes
(100%)
pororo/models/brainOCR/__pycache__/detection.cpython-311.pyc
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import requests | ||
import uuid | ||
import time | ||
import json | ||
import configparser | ||
|
||
|
||
from utils.nutrition_parser import parse_nutrients_from_text | ||
|
||
|
||
|
||
def clova_ocr(file, file_content): | ||
parser = configparser.ConfigParser() | ||
parser.read("./clova.conf") | ||
|
||
api_url = parser.get("clova_credentials", "API_URL") | ||
secret_key = parser.get("clova_credentials", "SECRET_KEY") | ||
|
||
request_json = { | ||
'images': [ | ||
{ | ||
'format': 'png', | ||
'name': 'demo' | ||
} | ||
], | ||
'requestId': str(uuid.uuid4()), | ||
'version': 'V2', | ||
'timestamp': int(round(time.time() * 1000)) | ||
} | ||
|
||
files = { | ||
'message': (None, json.dumps(request_json), 'application/json'), | ||
'file': (file.filename, file_content, file.content_type) | ||
} | ||
|
||
headers = { | ||
'X-OCR-SECRET': secret_key | ||
} | ||
payload = {'message': json.dumps(request_json).encode('UTF-8')} | ||
|
||
response = requests.request("POST", api_url, headers=headers, files=files) | ||
|
||
res = json.loads(response.text.encode('utf8')) | ||
print(res) | ||
|
||
# 결과에서 Text만 추출하여 출력하기 위한 코드 | ||
text = res['images'][0]['fields'] | ||
answer = '' | ||
|
||
# fileds 배열의 길이만큼 반복하면서 inferText 값을 담고 공백을 붙여줌 | ||
for i in range(len(text)): | ||
answer += text[i]['inferText'] + ' ' | ||
return parse_nutrients_from_text(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters