Spaces:
Running
Running
import gradio as gr | |
import pdfplumber | |
from transformers import pipeline | |
# Inicjalizacja modelu do ekstrakcji informacji | |
extractor = pipeline("ner", model="dslim/bert-base-NER") | |
def extract_info(pdf_file): | |
with pdfplumber.open(pdf_file) as pdf: | |
text = "" | |
for page in pdf.pages: | |
text += page.extract_text() + "\n" | |
# Przetwarzanie tekstu modelem NLP | |
entities = extractor(text) | |
# Filtrowanie i formatowanie wyników | |
extracted_data = {} | |
for entity in entities: | |
label = entity['entity'] | |
word = entity['word'] | |
if label not in extracted_data: | |
extracted_data[label] = [] | |
extracted_data[label].append(word) | |
return extracted_data | |
# Interfejs użytkownika w Hugging Face Space | |
iface = gr.Interface( | |
fn=extract_info, | |
inputs=gr.File(label="Wybierz plik PDF"), | |
outputs="json", | |
title="Ekstrakcja informacji z faktur PDF", | |
description="Prześlij plik PDF z fakturą, a model rozpozna kluczowe informacje." | |
) | |
if __name__ == "__main__": | |
iface.launch() | |