kryman27 commited on
Commit
ce53438
verified
1 Parent(s): 0332a57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -22
app.py CHANGED
@@ -1,37 +1,29 @@
1
  import gradio as gr
2
  import pdfplumber
3
- from transformers import pipeline
4
 
5
- # Inicjalizacja modelu NER
6
- extractor = pipeline("ner", model="dslim/bert-base-NER", aggregation_strategy="simple")
7
-
8
- def extract_info(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
- # Formatowanie wynik贸w
16
- extracted_data = {}
17
- for entity in entities:
18
- label = entity["entity_group"]
19
- word = entity["word"]
20
-
21
- if label not in extracted_data:
22
- extracted_data[label] = []
23
 
24
- extracted_data[label].append(word)
 
 
 
25
 
26
- return extracted_data
27
 
28
- # Interfejs u偶ytkownika w Hugging Face Space
29
  iface = gr.Interface(
30
- fn=extract_info,
31
  inputs=gr.File(label="Wybierz plik PDF"),
32
  outputs="json",
33
- title="Ekstrakcja informacji z faktur PDF",
34
- description="Prze艣lij plik PDF z faktur膮, a model rozpozna kluczowe informacje."
35
  )
36
 
37
  if __name__ == "__main__":
 
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(
22
+ fn=extract_seller,
23
  inputs=gr.File(label="Wybierz plik PDF"),
24
  outputs="json",
25
+ title="Ekstrakcja Sprzedawcy z Faktury",
26
+ description="Prze艣lij plik PDF, aby wydoby膰 nazw臋 sprzedawcy."
27
  )
28
 
29
  if __name__ == "__main__":