File size: 1,164 Bytes
58a3f69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- encoding: utf-8 -*-
# @Author: SWHL
# @Contact: liekkaskono@163.com
import os
os.system('pip install -r requirements.txt')

import cv2
import gradio as gr

from ctrnet_infer import CTRNetInfer


def inference(img_path):
    img = cv2.imread(img_path)
    pred = ctrnet(img)
    pred = cv2.cvtColor(pred, cv2.COLOR_BGR2RGB)
    return pred


model_path = 'models/CTRNet_G.onnx'
ctrnet = CTRNetInfer(model_path)

title = 'CTRNet Demo'
description = '''This is the demo for the paper “Don't Forget Me: Accurate Background Recovery for Text Removal via Modeling Local-Global Context”. Github Repo: https://github.com/lcy0604/CTRNet'''
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
examples = [['images/1.jpg'], ['images/2.jpg'], ['images/4.jpg']]

gr.Interface(
    inference,
    inputs=[
        gr.inputs.Image(type='filepath', label='Input'),
    ],
    outputs=[
        gr.outputs.Image(type='filepath', label='Output_image'),
    ],
    title=title,
    description=description,
    examples=examples,
    css=css,
    allow_flagging='never',
    enable_queue=True
    ).launch(debug=True, enable_queue=True)