Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from transformers import pipeline
|
4 |
-
|
5 |
-
# Inicjalizacja modelu
|
6 |
-
extractor = pipeline("ner", model="opendatalab/PDF-Extract-Kit")
|
7 |
|
8 |
def extract_info(pdf_file):
|
9 |
-
|
10 |
-
|
11 |
-
for page in pdf.pages:
|
12 |
-
text += page.extract_text()
|
13 |
|
14 |
-
# Przetwarzanie
|
15 |
-
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
results[label] = []
|
24 |
-
results[label].append(word)
|
25 |
|
26 |
-
return
|
27 |
|
28 |
# Interfejs u偶ytkownika
|
29 |
iface = gr.Interface(
|
30 |
fn=extract_info,
|
31 |
inputs=gr.inputs.File(label="Wybierz plik PDF"),
|
32 |
-
outputs=gr.outputs.JSON(label="
|
33 |
title="Ekstrakcja informacji z faktur PDF",
|
34 |
description="Prze艣lij plik PDF z faktur膮, aby wyodr臋bni膰 okre艣lone informacje."
|
35 |
)
|
|
|
1 |
import gradio as gr
|
2 |
+
from magic_pdf import MagicPDF
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def extract_info(pdf_file):
|
5 |
+
# Inicjalizacja MagicPDF
|
6 |
+
pdf_processor = MagicPDF()
|
|
|
|
|
7 |
|
8 |
+
# Przetwarzanie pliku PDF
|
9 |
+
result = pdf_processor(pdf_file.name)
|
10 |
|
11 |
+
# Wyodr臋bnianie po偶膮danych informacji
|
12 |
+
extracted_data = {
|
13 |
+
"company_name": result.get("company_name", "Nie znaleziono"),
|
14 |
+
"invoice_number": result.get("invoice_number", "Nie znaleziono"),
|
15 |
+
# Dodaj inne pola wed艂ug potrzeb
|
16 |
+
}
|
|
|
|
|
17 |
|
18 |
+
return extracted_data
|
19 |
|
20 |
# Interfejs u偶ytkownika
|
21 |
iface = gr.Interface(
|
22 |
fn=extract_info,
|
23 |
inputs=gr.inputs.File(label="Wybierz plik PDF"),
|
24 |
+
outputs=gr.outputs.JSON(label="Wyodr臋bnione informacje"),
|
25 |
title="Ekstrakcja informacji z faktur PDF",
|
26 |
description="Prze艣lij plik PDF z faktur膮, aby wyodr臋bni膰 okre艣lone informacje."
|
27 |
)
|