Spaces:
Running
Running
import gradio as gr | |
import pdfplumber | |
import re | |
def extract_seller(pdf_file): | |
with pdfplumber.open(pdf_file) as pdf: | |
text = "\n".join(page.extract_text() for page in pdf.pages if page.extract_text()) | |
# Szukamy linii zawierającej "Sprzedawca" | |
pattern = r"(Sprzedawca[:\s]+)(.+)" | |
match = re.search(pattern, text, re.IGNORECASE) | |
if match: | |
seller_name = match.group(2).strip() # Pobiera nazwę firmy po "Sprzedawca:" | |
else: | |
seller_name = "Nie znaleziono" | |
return {"Sprzedawca": seller_name} | |
# Interfejs użytkownika w Hugging Face Spaces | |
iface = gr.Interface( | |
fn=extract_seller, | |
inputs=gr.File(label="Wybierz plik PDF"), | |
outputs="json", | |
title="Ekstrakcja Sprzedawcy z Faktury", | |
description="Prześlij plik PDF, aby wydobyć nazwę sprzedawcy." | |
) | |
if __name__ == "__main__": | |
iface.launch() | |