Spaces:
Build error
Build error
update
Browse files
app.py
CHANGED
@@ -1,17 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
3 |
from huggingface_hub import snapshot_download
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
return
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from modelscope.pipelines import pipeline
|
3 |
+
from modelscope.utils.constant import Tasks
|
4 |
from huggingface_hub import snapshot_download
|
5 |
+
import os
|
6 |
+
|
7 |
+
# Step 1: Download the model
|
8 |
+
model_dir = snapshot_download('opendatalab/PDF-Extract-Kit-1.0')
|
9 |
|
10 |
+
# Step 2: Initialize pipeline
|
11 |
+
pipe = pipeline(
|
12 |
+
task=Tasks.document_segmentation,
|
13 |
+
model=model_dir
|
14 |
+
)
|
15 |
|
16 |
+
# Step 3: Define inference function
|
17 |
+
def extract_info_from_pdf(pdf_file):
|
18 |
+
result = pipe({'file': pdf_file.name})
|
19 |
+
return str(result)
|
20 |
|
21 |
+
# Step 4: Gradio UI
|
22 |
+
gr.Interface(
|
23 |
+
fn=extract_info_from_pdf,
|
24 |
+
inputs=gr.File(type="binary", label="Upload PDF"),
|
25 |
+
outputs="text",
|
26 |
+
title="PDF Extractor (PDF-Extract-Kit)"
|
27 |
+
).launch()
|