Spaces:
Running
Running
Upload 2 files
Browse files- app.py +93 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- encoding: utf-8 -*-
|
2 |
+
# @Author: SWHL
|
3 |
+
# @Contact: [email protected]
|
4 |
+
import shutil
|
5 |
+
import zipfile
|
6 |
+
from pathlib import Path
|
7 |
+
|
8 |
+
import streamlit as st
|
9 |
+
from rapid_videocr import RapidVideOCR
|
10 |
+
|
11 |
+
|
12 |
+
def mkdir(dir_path):
|
13 |
+
Path(dir_path).mkdir(parents=True, exist_ok=True)
|
14 |
+
|
15 |
+
|
16 |
+
st.markdown(
|
17 |
+
"<h1 style='text-align: center;'><a href='https://github.com/SWHL/RapidVideOCR' style='text-decoration: none'>RapidVideOCR</a></h1>",
|
18 |
+
unsafe_allow_html=True,
|
19 |
+
)
|
20 |
+
st.markdown(
|
21 |
+
"""
|
22 |
+
<p align="left">
|
23 |
+
<a href="https://colab.research.google.com/github/SWHL/RapidVideOCR/blob/75dae6e9804dec6e61bef98334601908dc9ec9fb/assets/RapidVideOCRDemo.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg"></a>
|
24 |
+
<a href=""><img src="https://img.shields.io/badge/Python->=3.6,<3.12-aff.svg"></a>
|
25 |
+
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
|
26 |
+
<a href="https://pypi.org/project/rapid-videocr/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapid_videocr"></a>
|
27 |
+
<a href="https://github.com/SWHL/RapidVideOCR/stargazers"><img src="https://img.shields.io/github/stars/SWHL/RapidVideOCR?color=ccf"></a>
|
28 |
+
<a href="https://pepy.tech/project/rapid-videocr"><img src="https://static.pepy.tech/personalized-badge/rapid-videocr?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads"></a>
|
29 |
+
<a href="https://semver.org/"><img alt="SemVer2.0" src="https://img.shields.io/badge/SemVer-2.0-brightgreen"></a>
|
30 |
+
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
|
31 |
+
</p>
|
32 |
+
""",
|
33 |
+
unsafe_allow_html=True,
|
34 |
+
)
|
35 |
+
|
36 |
+
img_suffix = [".png", ".jpeg", ".jpg"]
|
37 |
+
|
38 |
+
st.markdown("#### Whether to use the concat rec:")
|
39 |
+
is_concat_res = st.checkbox("is_concat_rec")
|
40 |
+
if is_concat_res:
|
41 |
+
number = st.number_input(
|
42 |
+
"Insert concat batch num",
|
43 |
+
value=10,
|
44 |
+
placeholder="Default is 10",
|
45 |
+
min_value=1,
|
46 |
+
max_value=20,
|
47 |
+
)
|
48 |
+
|
49 |
+
extractor = RapidVideOCR(
|
50 |
+
is_concat_rec=is_concat_res, out_format='srt', is_print_console=False
|
51 |
+
)
|
52 |
+
|
53 |
+
save_dir = Path("images")
|
54 |
+
mkdir(save_dir)
|
55 |
+
output_dir = Path("outputs")
|
56 |
+
save_file_dir = None
|
57 |
+
|
58 |
+
st.markdown("#### Upload ZIP files of RGBImages or TXTImages from VideoSubFinder:")
|
59 |
+
with st.form('my-form', clear_on_submit=True):
|
60 |
+
uploaded_file = st.file_uploader(
|
61 |
+
"Upload a ZIP file containg RGBImages or TXTImages folder.",
|
62 |
+
type=["zip"],
|
63 |
+
label_visibility="collapsed",
|
64 |
+
)
|
65 |
+
submitted = st.form_submit_button('Upload')
|
66 |
+
|
67 |
+
if submitted and uploaded_file is not None:
|
68 |
+
with zipfile.ZipFile(uploaded_file, "r") as zip_ref:
|
69 |
+
file_list = zip_ref.namelist()
|
70 |
+
for file_path in file_list:
|
71 |
+
if Path(file_path).suffix not in img_suffix:
|
72 |
+
continue
|
73 |
+
|
74 |
+
# 写到本地临时目录下
|
75 |
+
save_full_path = save_dir / file_path
|
76 |
+
|
77 |
+
save_file_dir = save_full_path.parent
|
78 |
+
save_file_dir.mkdir(parents=True, exist_ok=True)
|
79 |
+
with open(save_full_path, "wb") as f:
|
80 |
+
f.write(zip_ref.read(file_path))
|
81 |
+
with st.spinner('Extracting...'):
|
82 |
+
extractor(save_file_dir, output_dir)
|
83 |
+
|
84 |
+
srt_path = output_dir / "result.srt"
|
85 |
+
if srt_path is not None and srt_path.exists():
|
86 |
+
st.toast('Success!', icon='🎉')
|
87 |
+
with open(srt_path, "rb") as f:
|
88 |
+
is_download_srt = st.download_button(
|
89 |
+
"Download SRT File", data=f, file_name=Path(srt_path).name
|
90 |
+
)
|
91 |
+
if is_download_srt:
|
92 |
+
shutil.rmtree(str(srt_path.resolve().parent))
|
93 |
+
shutil.rmtree(str(save_file_dir.resolve().parent))
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
altair<5
|
2 |
+
rapidvideocr
|