File size: 866 Bytes
07d0354
814c19e
ce53438
814c19e
ce53438
814c19e
db576bd
07d0354
ce53438
 
 
db576bd
ce53438
 
 
 
07d0354
ce53438
07d0354
ce53438
07d0354
ce53438
814c19e
 
ce53438
 
07d0354
 
 
 
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
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()