SWHL commited on
Commit
0b4c299
·
verified ·
1 Parent(s): 305df7a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- encoding: utf-8 -*-
2
+ # @Author: SWHL
3
+ # @Contact: [email protected]
4
+ from typing import List
5
+
6
+ import gradio as gr
7
+ from gradio_pdf import PDF
8
+
9
+ from rapidocr_pdf import RapidOCRPDF
10
+
11
+ custom_css = """
12
+ body {font-family: body {font-family: 'Helvetica Neue', Helvetica;}
13
+ .gr-button {background-color: #4CAF50; color: white; border: none; padding: 10px 20px; border-radius: 5px;}
14
+ .gr-button:hover {background-color: #45a049;}
15
+ .gr-textbox {margin-bottom: 15px;}
16
+ .example-button {background-color: #1E90FF; color: white; border: none; padding: 8px 15px; border-radius: 5px; margin: 5px;}
17
+ .example-button:hover {background-color: #FF4500;}
18
+ .tall-radio .gr-radio-item {padding: 15px 0; min-height: 50px; display: flex; align-items: center;}
19
+ .tall-radio label {font-size: 16px;}
20
+ .output-image, .input-image, .image-preview {height: 300px !important}
21
+ """
22
+
23
+ pdf_extracter = RapidOCRPDF()
24
+
25
+
26
+ def get_pdf_result(pdf_path: str, page_num: int = 0):
27
+ return pdf_extracter(pdf_path, page_num_list=[page_num])
28
+
29
+
30
+ with gr.Blocks(
31
+ title="RapidOCR 📄 PDF", css="custom_css", theme=gr.themes.Soft()
32
+ ) as demo:
33
+ gr.Markdown(
34
+ "<h1 style='text-align: center;'><a href='https://github.com/RapidAI/RapidOCRPDF' style='text-decoration: none;'>RapidOCR 📄 PDF</a></h1>"
35
+ )
36
+ gr.HTML(
37
+ """
38
+ <div style="display: flex; justify-content: center; gap: 10px;">
39
+ <a href=""><img src="https://img.shields.io/badge/Python->=3.6-aff.svg"></a>
40
+ <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
41
+ <a href="https://pypi.org/project/rapidocr-pdf/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapidocr-pdf"></a>
42
+ <a href="https://pepy.tech/project/rapidocr-pdf"><img src="https://static.pepy.tech/personalized-badge/rapidocr-pdf?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads"></a>
43
+ <a href="https://semver.org/"><img alt="SemVer2.0" src="https://img.shields.io/badge/SemVer-2.0-brightgreen"></a>
44
+ <a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
45
+ <a href="https://choosealicense.com/licenses/apache-2.0/"><img alt="GitHub" src="https://img.shields.io/github/license/RapidAI/RapidOCRPDF"></a>
46
+ </div>
47
+ """
48
+ )
49
+
50
+ pdf_path = PDF(label="Upload a PDF", interactive=True)
51
+ page_num = gr.Number(value=0, label="Select Extract Page", minimum=0, maximum=5)
52
+ btn = gr.Button("Run")
53
+ results = gr.Dataframe(
54
+ label="PDF Extract Results",
55
+ headers=["Index", "Txt", "Score"],
56
+ datatype=["number", "str", "number"],
57
+ show_copy_button=True,
58
+ show_fullscreen_button=True,
59
+ )
60
+ btn.click(get_pdf_result, inputs=[pdf_path, page_num], outputs=[results])
61
+
62
+
63
+ if __name__ == "__main__":
64
+ demo.launch()