Spaces:
Running
Running
File size: 1,148 Bytes
07d0354 814c19e 061d5cb 10213d3 88ffdd7 814c19e 88ffdd7 814c19e 88ffdd7 159c760 07d0354 88ffdd7 10213d3 88ffdd7 db576bd 88ffdd7 9f38b98 88ffdd7 9f38b98 88ffdd7 9f38b98 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import gradio as gr
import pdfplumber
import re
from transformers import pipeline
# Model do analizy układu faktur
extractor = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
def extract_seller_data(pdf_file):
with pdfplumber.open(pdf_file) as pdf:
# Pobranie całego tekstu z PDF
full_text = "\n".join(page.extract_text() for page in pdf.pages if page.extract_text())
# Zadawanie pytania modelowi → pytamy o cały blok danych sprzedawcy
question = "What is the seller's information?"
response = extractor(question=question, context=full_text)
# Model zwraca tekst, który uznał za odpowiedź na pytanie
seller_info = response[0]["answer"] if response else "Nie znaleziono"
return {"Sprzedawca": seller_info}
# Interfejs użytkownika w Hugging Face Spaces
iface = gr.Interface(
fn=extract_seller_data,
inputs=gr.File(label="Wybierz plik PDF"),
outputs="json",
title="Ekstrakcja danych sprzedawcy z faktury",
description="Prześlij plik PDF, a model zwróci kompletny zestaw danych o sprzedawcy."
)
if __name__ == "__main__":
iface.launch()
|