Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- encoding: utf-8 -*-
|
| 2 |
+
# @Author: SWHL
|
| 3 |
+
# @Contact: liekkaskono@163.com
|
| 4 |
+
import numpy as np
|
| 5 |
+
import streamlit as st
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
from rapid_layout import RapidLayout, VisLayout
|
| 9 |
+
|
| 10 |
+
layout_engine = RapidLayout()
|
| 11 |
+
|
| 12 |
+
st.markdown(
|
| 13 |
+
"<h1 style='text-align: center;'><a href='https://github.com/RapidAI/RapidLayout' style='text-decoration: none'>Rapid Layout</a></h1>",
|
| 14 |
+
unsafe_allow_html=True,
|
| 15 |
+
)
|
| 16 |
+
st.markdown(
|
| 17 |
+
"""
|
| 18 |
+
<p align="left">
|
| 19 |
+
<a href=""><img src="https://img.shields.io/badge/Python->=3.6,<3.13-aff.svg"></a>
|
| 20 |
+
<a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
|
| 21 |
+
<a href="https://pypi.org/project/rapid-layout/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapid-layout"></a>
|
| 22 |
+
<a href="https://pepy.tech/project/rapid-layout"><img src="https://static.pepy.tech/personalized-badge/rapid-layout?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads"></a>
|
| 23 |
+
<a href="https://semver.org/"><img alt="SemVer2.0" src="https://img.shields.io/badge/SemVer-2.0-brightgreen"></a>
|
| 24 |
+
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
|
| 25 |
+
</p>
|
| 26 |
+
""",
|
| 27 |
+
unsafe_allow_html=True,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
model_types = {
|
| 31 |
+
"pp_layout_cdla": [
|
| 32 |
+
"text",
|
| 33 |
+
"title",
|
| 34 |
+
"figure",
|
| 35 |
+
"figure_caption",
|
| 36 |
+
"table",
|
| 37 |
+
"table_caption",
|
| 38 |
+
"header",
|
| 39 |
+
"footer",
|
| 40 |
+
"reference",
|
| 41 |
+
"equation",
|
| 42 |
+
],
|
| 43 |
+
"pp_layout_publaynet": ["text", "title", "list", "table", "figure"],
|
| 44 |
+
"pp_layout_table": ["table"],
|
| 45 |
+
"yolov8n_layout_paper": [
|
| 46 |
+
"text",
|
| 47 |
+
"title",
|
| 48 |
+
"figure",
|
| 49 |
+
"figure_caption",
|
| 50 |
+
"table",
|
| 51 |
+
"table_caption",
|
| 52 |
+
"header",
|
| 53 |
+
"footer",
|
| 54 |
+
"reference",
|
| 55 |
+
"equation",
|
| 56 |
+
],
|
| 57 |
+
"yolov8n_layout_report": [
|
| 58 |
+
"text",
|
| 59 |
+
"title",
|
| 60 |
+
"header",
|
| 61 |
+
"footer",
|
| 62 |
+
"figure",
|
| 63 |
+
"figure_caption",
|
| 64 |
+
"table",
|
| 65 |
+
"table_caption",
|
| 66 |
+
"toc",
|
| 67 |
+
],
|
| 68 |
+
}
|
| 69 |
+
option = st.selectbox("选择版面分析模型:", model_types.keys())
|
| 70 |
+
st.write("支持检测类型:")
|
| 71 |
+
st.code(model_types[option], language="python")
|
| 72 |
+
|
| 73 |
+
st.write("请上传图像:")
|
| 74 |
+
img_suffix = ["png", "jpg", "jpeg"]
|
| 75 |
+
img_file_buffer = st.file_uploader(
|
| 76 |
+
"Upload an image", type=img_suffix, key="layout", label_visibility="collapsed"
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
if img_file_buffer:
|
| 80 |
+
image = Image.open(img_file_buffer)
|
| 81 |
+
img = np.array(image)
|
| 82 |
+
boxes, scores, class_names, *elapse = layout_engine(img)
|
| 83 |
+
ploted_img = VisLayout.draw_detections(img, boxes, scores, class_names)
|
| 84 |
+
|
| 85 |
+
st.image(ploted_img, use_column_width=True)
|