holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.72k stars 513 forks source link

Cannot upload accepted_filetypes pdf #7407

Closed MarcSkovMadsen closed 3 hours ago

MarcSkovMadsen commented 3 hours ago

I'm on panel 1.5.2 using the FileDropper and try to make a working example for https://discourse.holoviz.org/t/problem-with-accessing-pdf-file-s-input-in-panel/8339.

image

import io
import panel as pn
import base64
from PyPDF2 import PdfReader

pn.extension('filedropper')

def transform_pdfs(value):
    pages = {}
    for key, value in value:
        f=io.BytesIO(file_input.value)
        reader = PdfReader(f)
        page = reader.pages[0]
        pages[key]=page
        print(pages)

file_input = pn.widgets.FileDropper(accepted_filetypes=[".pdf"])

pn.Column(
    file_input, pn.bind(transform_pdfs, file_input)
).servable()

I've also tried accepted_filetypes=["pdf"] without success.

philippjfr commented 3 hours ago

Duplicate: https://github.com/holoviz/panel/issues/7153

MarcSkovMadsen commented 3 hours ago

I was a little bit sad to see that the .value parameter of the FileDropper is not the same as the FileInput. For its important to recognize that long term there will be a lot of different specialized FileInput widgets for different types of media - Like FileInput, FileDropper, ImageInput, TabularInput, VideoInput, AudioInput etc. Their value will all be one or more files. Those widgets should be a family of widgets with the same python api to make them easy to use. At least that is what Gradio has recognized is helping their users.