Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import shutil
|
| 4 |
+
import main
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def predict_from_pdf(pdf_file):
|
| 8 |
+
upload_dir = "./catalogue/"
|
| 9 |
+
os.makedirs(upload_dir, exist_ok=True)
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
dest_path = os.path.join(upload_dir, pdf_file.name)
|
| 13 |
+
with open(dest_path, "wb") as f:
|
| 14 |
+
f.write(pdf_file.read())
|
| 15 |
+
|
| 16 |
+
df, response = main_oss.process_pdf_catalog(dest_path)
|
| 17 |
+
return df, response
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return None, f"Error: {str(e)}"
|
| 20 |
+
|
| 21 |
+
pdf_examples = [
|
| 22 |
+
["examples/flexpocket.pdf"],
|
| 23 |
+
["examples/ASICS_Catalog.pdf"],
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=predict_from_pdf,
|
| 28 |
+
inputs=gr.File(label="Upload PDF Catalog"),
|
| 29 |
+
outputs=["json", "text"],
|
| 30 |
+
examples=pdf_examples,
|
| 31 |
+
title="Open Source PDF Catalog Parser",
|
| 32 |
+
description="Efficient PDF catalog processing using MinerU and OpenLLM",
|
| 33 |
+
article="Uses MinerU for layout analysis and DeepSeek-1.3B for structured extraction"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860)
|