Spaces:
Build error
Build error
First model version
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
#os.system('python setup.py build develop')
|
| 3 |
+
os.system('pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"')
|
| 4 |
+
os.system('pip install --upgrade --no-cache-dir gdown')
|
| 5 |
+
os.system('gdown -O output/ctw/ 1Ajslu_9WisuZ2nJGzE6qbD87aK6_ozzA')
|
| 6 |
+
|
| 7 |
+
import cv2
|
| 8 |
+
import pandas as pd
|
| 9 |
+
import gradio as gr
|
| 10 |
+
from tools.demo import TextDemo
|
| 11 |
+
from maskrcnn_benchmark.config import cfg
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def infer(filepath):
|
| 15 |
+
cfg.merge_from_file('configs/ctw/r50_baseline.yaml')
|
| 16 |
+
# manual override some options
|
| 17 |
+
cfg.merge_from_list(["MODEL.DEVICE", "cpu"])
|
| 18 |
+
|
| 19 |
+
text_demo = TextDemo(
|
| 20 |
+
cfg,
|
| 21 |
+
min_image_size=800,
|
| 22 |
+
confidence_threshold=0.7,
|
| 23 |
+
output_polygon=True
|
| 24 |
+
)
|
| 25 |
+
image = cv2.imread(filepath)
|
| 26 |
+
result_polygons, result_masks = text_demo.run_on_opencv_image(image)
|
| 27 |
+
image = text_demo.visualization(image, result_polygons, result_masks)
|
| 28 |
+
cv2.imwrite('result.jpg', image)
|
| 29 |
+
return 'result.jpg'#, pd.DataFrame(result_words)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
iface = gr.Interface(
|
| 33 |
+
fn=infer,
|
| 34 |
+
title="Mask TextSpotter v3",
|
| 35 |
+
description="Mask TextSpotter v3 is an end-to-end trainable scene text spotter that adopts a Segmentation Proposal Network (SPN) instead of an RPN. Mask TextSpotter v3 significantly improves robustness to rotations, aspect ratios, and shapes.",
|
| 36 |
+
inputs=[gr.inputs.Image(label="image", type="filepath")],
|
| 37 |
+
outputs=[gr.outputs.Image()], #, gr.outputs.Dataframe(headers=['word'])],
|
| 38 |
+
#examples=['example1.jpg', 'example2.jpg', 'example3.jpg'],
|
| 39 |
+
#article="<a href=\"https://github.com/MhLiao/MaskTextSpotterV3\">GitHub Repo</a>",
|
| 40 |
+
).launch(enable_queue=True, cache_examples=True)
|