kryman27 commited on
Commit
10213d3
·
verified ·
1 Parent(s): 6c54caf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -1,21 +1,25 @@
1
  import gradio as gr
2
  import pdfplumber
3
- import re
 
 
 
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
- # Szukamy linii zawierającej "Sprzedawca"
10
- pattern = r"(Sprzedawca[:\s]+)(.+)"
11
- match = re.search(pattern, text, re.IGNORECASE)
 
12
 
13
- if match:
14
- seller_name = match.group(2).strip() # Pobiera nazwę firmy po "Sprzedawca:"
15
- else:
16
- seller_name = "Nie znaleziono"
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(