kryman27 commited on
Commit
7bd59d8
verified
1 Parent(s): 07d0354

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -1,35 +1,27 @@
1
  import gradio as gr
2
- import pdfplumber
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
- with pdfplumber.open(pdf_file) as pdf:
10
- text = ""
11
- for page in pdf.pages:
12
- text += page.extract_text()
13
 
14
- # Przetwarzanie tekstu za pomoc膮 modelu
15
- entities = extractor(text)
16
 
17
- # Filtrowanie i formatowanie wynik贸w
18
- results = {}
19
- for entity in entities:
20
- label = entity['entity']
21
- word = entity['word']
22
- if label not in results:
23
- results[label] = []
24
- results[label].append(word)
25
 
26
- return results
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="Wykryte informacje"),
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
  )