Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import pdfplumber
|
3 |
-
import
|
|
|
|
|
|
|
4 |
|
5 |
def extract_seller(pdf_file):
|
6 |
with pdfplumber.open(pdf_file) as pdf:
|
7 |
text = "\n".join(page.extract_text() for page in pdf.pages if page.extract_text())
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
return {"Sprzedawca": seller_name}
|
19 |
|
20 |
# Interfejs użytkownika w Hugging Face Spaces
|
21 |
iface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
import pdfplumber
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Inicjalizacja modelu LayoutLM do ekstrakcji tekstu
|
6 |
+
extractor = pipeline("ner", model="microsoft/layoutlmv3-base", aggregation_strategy="simple")
|
7 |
|
8 |
def extract_seller(pdf_file):
|
9 |
with pdfplumber.open(pdf_file) as pdf:
|
10 |
text = "\n".join(page.extract_text() for page in pdf.pages if page.extract_text())
|
11 |
|
12 |
+
# Przetwarzanie tekstu modelem NLP
|
13 |
+
entities = extractor(text)
|
14 |
+
|
15 |
+
seller_name = None
|
16 |
|
17 |
+
for entity in entities:
|
18 |
+
if "ORG" in entity["entity_group"]: # Szukamy nazw organizacji
|
19 |
+
seller_name = entity["word"]
|
20 |
+
break # Pobieramy pierwszą wykrytą firmę jako sprzedawcę
|
21 |
|
22 |
+
return {"Sprzedawca": seller_name if seller_name else "Nie znaleziono"}
|
23 |
|
24 |
# Interfejs użytkownika w Hugging Face Spaces
|
25 |
iface = gr.Interface(
|