votecount-ml-be / main.py
napatswift's picture
Update main.py
ca7a62e
raw
history blame
785 Bytes
from mmocr.apis import MMOCRInferencer
import gradio as gr
import cv2
import sys
import torch
device = 'gpu' if torch.cuda.is_available() else 'cpu'
ocr = MMOCRInferencer(det='model/det/config.py',
det_weights='model/det/model.pth',
device=device)
def get_rec(points):
xs = []
ys = []
for ix, iv in enumerate(points):
if ix % 2:
ys.append(iv)
else:
xs.append(iv)
return (min(xs), min(ys)), (max(xs), max(ys))
def predict(image_input):
return ocr(image_input)
def run():
demo = gr.Interface(
fn=predict,
inputs=gr.components.Image(),
outputs=gr.JSON(),
)
demo.launch(server_name="0.0.0.0", server_port=7860)
if __name__ == "__main__":
run()