Spaces:
Sleeping
Sleeping
Allow adjustable page slider up to 10 pages for CPU demo
Browse files
app.py
CHANGED
|
@@ -1,6 +1,63 @@
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
from loguru import logger
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
if __name__ == '__main__':
|
| 6 |
os.system('pip uninstall -y mineru')
|
|
@@ -21,9 +78,12 @@ if __name__ == '__main__':
|
|
| 21 |
config['llm-aided-config']['title_aided']['api_key'] = os.getenv('apikey')
|
| 22 |
config['llm-aided-config']['title_aided']['enable'] = True
|
| 23 |
|
| 24 |
-
file.seek(0)
|
| 25 |
-
file.truncate()
|
| 26 |
-
json.dump(config, file, indent=4)
|
| 27 |
except Exception as e:
|
| 28 |
logger.exception(e)
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
from loguru import logger
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from mineru.cli.gradio_app import *
|
| 6 |
+
|
| 7 |
+
# Override the original gradio interface to fix slider issue
|
| 8 |
+
def create_interface():
|
| 9 |
+
# Use the original functions but fix the max_pages slider
|
| 10 |
+
with gr.Blocks(title="MinerU - CPU Demo") as demo:
|
| 11 |
+
with gr.Row():
|
| 12 |
+
with gr.Column():
|
| 13 |
+
# File upload
|
| 14 |
+
pdf_file = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 15 |
+
|
| 16 |
+
# Backend selection - remove SGLang options for CPU
|
| 17 |
+
backend = gr.Dropdown(
|
| 18 |
+
choices=["pipeline", "vlm-transformers"],
|
| 19 |
+
value="pipeline",
|
| 20 |
+
label="Backend"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Formula and table recognition
|
| 24 |
+
formula = gr.Checkbox(label="Formula", value=True)
|
| 25 |
+
table = gr.Checkbox(label="Table", value=True)
|
| 26 |
+
|
| 27 |
+
# Language selection
|
| 28 |
+
lang = gr.Dropdown(
|
| 29 |
+
choices=["en", "zh"],
|
| 30 |
+
value="en",
|
| 31 |
+
label="Language"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Max pages - adjustable for CPU demo
|
| 35 |
+
max_pages = gr.Slider(
|
| 36 |
+
1, 10, 1, # min=1, max=10, default=1
|
| 37 |
+
step=1,
|
| 38 |
+
label='Max convert pages (CPU Demo: up to 10 pages)'
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Convert button
|
| 42 |
+
convert_btn = gr.Button("Convert to Markdown", variant="primary")
|
| 43 |
+
|
| 44 |
+
with gr.Column():
|
| 45 |
+
# Output
|
| 46 |
+
output_file = gr.File(label="Download Result")
|
| 47 |
+
markdown_output = gr.Textbox(
|
| 48 |
+
label="Markdown Content",
|
| 49 |
+
lines=20,
|
| 50 |
+
max_lines=30
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# Convert function
|
| 54 |
+
convert_btn.click(
|
| 55 |
+
fn=to_markdown,
|
| 56 |
+
inputs=[pdf_file, backend, formula, table, lang, max_pages],
|
| 57 |
+
outputs=[output_file, markdown_output]
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
return demo
|
| 61 |
|
| 62 |
if __name__ == '__main__':
|
| 63 |
os.system('pip uninstall -y mineru')
|
|
|
|
| 78 |
config['llm-aided-config']['title_aided']['api_key'] = os.getenv('apikey')
|
| 79 |
config['llm-aided-config']['title_aided']['enable'] = True
|
| 80 |
|
| 81 |
+
file.seek(0)
|
| 82 |
+
file.truncate()
|
| 83 |
+
json.dump(config, file, indent=4)
|
| 84 |
except Exception as e:
|
| 85 |
logger.exception(e)
|
| 86 |
+
|
| 87 |
+
# Launch custom interface instead of command line
|
| 88 |
+
demo = create_interface()
|
| 89 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|