kryman27 commited on
Commit
07d0354
verified
1 Parent(s): 49c7f51

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ )
36
+
37
+ if __name__ == "__main__":
38
+ iface.launch()