Spaces:
Running
Running
Update app
Browse files
app.py
CHANGED
|
@@ -1,28 +1,58 @@
|
|
| 1 |
# -*- encoding: utf-8 -*-
|
| 2 |
# @Author: SWHL
|
| 3 |
# @Contact: liekkaskono@163.com
|
| 4 |
-
import streamlit as st
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
| 9 |
converter = PaddleOCRModelConvert()
|
| 10 |
|
| 11 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
url = st.text_input('输入模型地址:',
|
| 16 |
|
| 17 |
-
|
| 18 |
-
txt_url = st.text_input('输入txt地址(文本识别模型时,必选):',
|
| 19 |
|
| 20 |
save_dir = 'models'
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# -*- encoding: utf-8 -*-
|
| 2 |
# @Author: SWHL
|
| 3 |
# @Contact: liekkaskono@163.com
|
|
|
|
| 4 |
|
| 5 |
+
import shutil
|
| 6 |
+
from pathlib import Path
|
| 7 |
|
| 8 |
+
import streamlit as st
|
| 9 |
+
from paddleocr_convert import PaddleOCRModelConvert
|
| 10 |
|
| 11 |
converter = PaddleOCRModelConvert()
|
| 12 |
|
| 13 |
+
st.markdown("<h1 style='text-align: center;'><a href='https://github.com/RapidAI/PaddleOCRModelConverter' style='text-decoration: none'>PaddleOCRModelConverter</a></h1>", unsafe_allow_html=True)
|
| 14 |
+
st.markdown("""
|
| 15 |
+
<p>
|
| 16 |
+
<a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
|
| 17 |
+
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
|
| 18 |
+
<a href="https://pypi.org/project/paddleocr_convert/"><img alt="PyPI" src="https://img.shields.io/pypi/v/paddleocr_convert"></a>
|
| 19 |
+
<a href="https://pepy.tech/project/paddleocr_convert"><img src="https://static.pepy.tech/personalized-badge/paddleocr_convert?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads"></a>
|
| 20 |
+
<a href='https://paddleocrmodelconverter.readthedocs.io/en/latest/?badge=latest'>
|
| 21 |
+
<img src='https://readthedocs.org/projects/paddleocrmodelconverter/badge/?version=latest' alt='Documentation Status' />
|
| 22 |
+
</a>
|
| 23 |
+
</p>
|
| 24 |
+
|
| 25 |
+
""", unsafe_allow_html=True)
|
| 26 |
|
| 27 |
+
st.markdown('戳这里查看支持模型列表:[PaddleOCR Models](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/models_list.md)')
|
| 28 |
|
| 29 |
+
default_url = 'e.g. https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar'
|
| 30 |
+
url = st.text_input('输入模型地址:', help=default_url)
|
| 31 |
|
| 32 |
+
default_txt_path = 'e.g. https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.6/ppocr/utils/ppocr_keys_v1.txt'
|
| 33 |
+
txt_url = st.text_input('输入txt地址(文本识别模型时,必选):', help=default_txt_path)
|
| 34 |
|
| 35 |
save_dir = 'models'
|
| 36 |
+
save_onnx_path = ''
|
| 37 |
+
|
| 38 |
+
is_convert = st.button('Convert')
|
| 39 |
+
if is_convert:
|
| 40 |
+
if not url or len(url) <= 0:
|
| 41 |
+
st.error('模型链接不能为空!')
|
| 42 |
+
st.stop()
|
| 43 |
+
|
| 44 |
+
if 'rec' in url and not txt_url:
|
| 45 |
+
st.error('识别模型对应字典不能为空')
|
| 46 |
+
st.stop()
|
| 47 |
+
|
| 48 |
+
save_onnx_path = converter(url, save_dir,
|
| 49 |
+
txt_path=txt_url,
|
| 50 |
+
is_del_raw=True)
|
| 51 |
+
st.success('转换成功,点击Download下载!', icon="✅")
|
| 52 |
+
|
| 53 |
+
if save_onnx_path:
|
| 54 |
+
with open(save_onnx_path, 'rb') as file:
|
| 55 |
+
is_download = st.download_button('Download', data=file,
|
| 56 |
+
file_name=Path(save_onnx_path).name)
|
| 57 |
+
if is_download:
|
| 58 |
+
shutil.rmtree(str(Path(save_onnx_path).resolve().parent))
|