L iQUddlmZddlmZddlmZddlmZmZm Z m Z m Z ddl m Z ddlmZmZddlmZddlmZmZmZdd lmZmZdd lmZmZmZmZmZdd l m!Z"dd l m#Z$dd l%m&Z'ddl(m)Z)ddl*m+Z+m,Z,ddl-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4er ddl5m6Z6ddl7m8Z8e4e3ze9e4e3zzdzZ:de;d<eeGddZ?GddZ@y)) annotations) dataclass)dedent) TYPE_CHECKINGLiteral TypeAliascastoverload)config)enforce_filename_restrictionnormalize_upload_file_type)current_form_id) LayoutConfigWidthWithoutContentvalidate_width)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)FileUploaderState)UploadedFileInfo) FileUploader)gather_metrics)ScriptRunContextget_script_run_ctx) WidgetArgsWidgetCallback WidgetKwargsregister_widget) DeletedFile UploadedFile)Sequence)DeltaGeneratorNrSomeUploadedFiles directoryAcceptMultipleFilesc |gSt}|gS|j}t|dk(rgS|jj |j |Dcgc]}|j c}}|Dcic]}|j |}}g}|D]k}|j|j }|(t||j}|j|H|jt|j m|Scc}wcc}w)Nr) session_idfile_ids) ruploaded_file_infolenuploaded_file_mgr get_filesr+file_idgetr$ file_urlsappendr#) widget_valuectxr-ffile_recs_list file_recscollected_filesmaybe_file_rec uploaded_files n/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/widgets/file_uploader.py_get_upload_filesr>Hs  C { %88 !# **44>>%78!))85N (66!A6I68:O ;"qyy1  %(EM  " "= 1  " ";qyy#9 : ; 97s C< 2Dc6eZdZUded<dZded<ddZd dZy) FileUploaderSerder)accept_multiple_filesNzSequence[str] | None allowed_typesc&t|}|D]@}t|tr|js!t |j |jB|j duxs|j dk(}t|dk(r |rg}|Sd}|S|r|n|d}|S)NTr(r)r> isinstancer#rBr namerAr.)selfui_value upload_filesfileis_multiple_or_directory return_values r= deserializezFileUploaderSerde.deserializeos(2   LD$ ,!!,TYY8J8JK  L  & &$ . 9))[8 ! |  !4LbLSWL,D<VWLc\t}|s|St|ts|g}|D]}t|tr|jj }|j |_|j|_|j|_|jj|j|SN) FileUploaderStateProtorDlistr#r-addr1rEsizer3CopyFrom _file_urls)rFfiles state_protor7 file_infos r= serializezFileUploaderSerde.serializes,.  %&GE 7A![)/:/M/M/Q/Q/SI ! I VVINVVIN    ( ( 6 7rM)rGFileUploaderStateProto | Nonereturnr')rVr'r[rP)__name__ __module__ __qualname____annotations__rBrLrYrMr=r@r@js..*.M'.,rMr@c 6eZdZe ddddd ddZe ddddd ddZedddddddddd dd Zeddddddddddd dd Zed  ddddd dd Z dddddd ddZeddZy)FileUploaderMixinNFvisiblestretch)disabledlabel_visibilitywidthc yrOr` rFlabeltyperAkeyhelp on_changeargskwargsrerfrgs r= file_uploaderzFileUploaderMixin.file_uploader!rMc yrOr`ris r=rqzFileUploaderMixin.file_uploader"rM) rkrlrmrnrorprerfrgc yrOr` rFrjrArkrlrmrnrorprerfrgs r=rqzFileUploaderMixin.file_uploaderrrrM) rArkrlrmrnrorprerfrgc yrOr`rvs r=rqzFileUploaderMixin.file_uploaderrtrMrqc Pt} |j||||||||| | | |  S)a%Display a file uploader widget. By default, uploaded files are limited to 200 MB each. You can configure this using the ``server.maxUploadSize`` config option. For more information on how to set config options, see |config.toml|_. .. |config.toml| replace:: ``config.toml`` .. _config.toml: https://docs.streamlit.io/develop/api-reference/configuration/config.toml Parameters ---------- label : str A short label explaining to the user what this file uploader is for. The label can optionally contain GitHub-flavored Markdown of the following types: Bold, Italics, Strikethroughs, Inline Code, Links, and Images. Images display like icons, with a max height equal to the font height. Unsupported Markdown elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g., ``"1\. Not an ordered list"``. See the ``body`` parameter of |st.markdown|_ for additional, supported Markdown directives. For accessibility reasons, you should never set an empty label, but you can hide it with ``label_visibility`` if needed. In the future, we may disallow empty labels by raising an exception. .. |st.markdown| replace:: ``st.markdown`` .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown type : str, list of str, or None The allowed file extension(s) for uploaded files. This can be one of the following types: - ``None`` (default): All file extensions are allowed. - A string: A single file extension is allowed. For example, to only accept CSV files, use ``"csv"``. - A sequence of strings: Multiple file extensions are allowed. For example, to only accept JPG/JPEG and PNG files, use ``["jpg", "jpeg", "png"]``. .. note:: This is a best-effort check, but doesn't provide a security guarantee against users uploading files of other types or type extensions. The correct handling of uploaded files is part of the app developer's responsibility. accept_multiple_files : bool or "directory" Whether to accept more than one file in a submission. This can be one of the following values: - ``False`` (default): The user can only submit one file at a time. - ``True``: The user can upload multiple files at the same time. - ``"directory"``: The user can select a directory to upload all files in the directory and its subdirectories. If ``type`` is set, only files matching those type(s) will be uploaded. When this is ``True`` or ``"directory"``, the return value will be a list and a user can additively select files if they click the browse button on the widget multiple times. key : str or int An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. No two widgets may have the same key. help : str or None A tooltip that gets displayed next to the widget label. Streamlit only displays the tooltip when ``label_visibility="visible"``. If this is ``None`` (default), no tooltip is displayed. The tooltip can optionally contain GitHub-flavored Markdown, including the Markdown directives described in the ``body`` parameter of ``st.markdown``. on_change : callable An optional callback invoked when this file_uploader's value changes. args : list or tuple An optional list or tuple of args to pass to the callback. kwargs : dict An optional dict of kwargs to pass to the callback. disabled : bool An optional boolean that disables the file uploader if set to ``True``. The default is ``False``. label_visibility : "visible", "hidden", or "collapsed" The visibility of the label. The default is ``"visible"``. If this is ``"hidden"``, Streamlit displays an empty spacer instead of the label, which can help keep the widget aligned with other widgets. If this is ``"collapsed"``, Streamlit displays no label or spacer. width : "stretch" or int The width of the file uploader widget. This can be one of the following: - ``"stretch"`` (default): The width of the widget matches the width of the parent container. - An integer specifying the width in pixels: The widget has a fixed width. If the specified width is greater than the width of the parent container, the width of the widget matches the width of the parent container. Returns ------- None, UploadedFile, or list of UploadedFile - If accept_multiple_files is ``False``, returns either ``None`` or an ``UploadedFile`` object. - If accept_multiple_files is ``True`` or ``"directory"``, returns a list with the uploaded files as ``UploadedFile`` objects. If no files were uploaded, returns an empty list. The ``UploadedFile`` class is a subclass of ``BytesIO``, and therefore is "file-like". This means you can pass an instance of it anywhere a file is expected. Examples -------- **Example 1: Accept a single file at a time** >>> import streamlit as st >>> import pandas as pd >>> from io import StringIO >>> >>> uploaded_file = st.file_uploader("Choose a file") >>> if uploaded_file is not None: ... # To read file as bytes: ... bytes_data = uploaded_file.getvalue() ... st.write(bytes_data) >>> ... # To convert to a string based IO: ... stringio = StringIO(uploaded_file.getvalue().decode("utf-8")) ... st.write(stringio) >>> ... # To read file as string: ... string_data = stringio.read() ... st.write(string_data) >>> ... # Can be used wherever a "file-like" object is accepted: ... dataframe = pd.read_csv(uploaded_file) ... st.write(dataframe) **Example 2: Accept multiple files at a time** >>> import pandas as pd >>> import streamlit as st >>> >>> uploaded_files = st.file_uploader( ... "Upload data", accept_multiple_files=True, type="csv" ... ) >>> for uploaded_file in uploaded_files: ... df = pd.read_csv(uploaded_file) ... st.write(df) .. output:: https://doc-file-uploader.streamlit.app/ height: 375px **Example 3: Accept an entire directory** >>> import streamlit as st >>> >>> uploaded_files = st.file_uploader( ... "Upload images", accept_multiple_files="directory", type=["jpg", "png"] ... ) >>> for uploaded_file in uploaded_files: ... st.image(uploaded_file) .. output:: https://doc-file-uploader-directory.streamlit.app/ height: 375px ) rjrkrArlrmrnrorprerfrgr6)r_file_uploader) rFrjrkrArlrmrnrorprerfrgr6s r=rqzFileUploaderMixin.file_uploadersID!""""7-#  rM)rfrer6rgc  t|}t|j||ddt|| t d|d|j|||||  } |r t |nd}t }| |_||_||ng|jddtjd|_ |dk(}|duxs||_ ||_t|j|_| |_t%| |j&_|t+||_t/||}t1|j||||j2|j4| d }t7| t9| }|jj;d|| t=|j(t>ryt=|j(t@r+|j(Dcgc]}t=|t>r|c}S|j(Scc}w) NF) default_valuewrites_allowedrq)user_keykey_as_main_identitydgrjrkrArmrgzserver.maxUploadSizer(T)rBfile_uploader_state_value)on_change_handlerrorp deserializer serializerr6 value_type)rg) layout_config)!rrrrrr FileUploaderProtoidrjrkr get_optionmax_upload_size_mbmultiple_filesaccept_directoryrform_idrerrfvaluerrmr@r"rLrYrr_enqueuerDr#rQ)rFrjrkrArlrmrnrorprfrer6rg element_idnormalized_typefile_uploader_protois_directory_uploadserde widget_staterr7s r=ryz FileUploaderMixin._file_uploaders Sk GG     #5*:;4 !&ww"7  ?C4T:/1!+$)!.:O   #281B1B "2 .4{B !T ) @-@ *0C,&5dgg&>#'/$5U 6 ,,2  '-d|  $!"7W '  " "'**2   u$51   0    l((+ 6 l(($ /+11T!A{9SAT T!!!Us G)G)ctd|S)zGet our DeltaGenerator.r&)r )rFs r=rzFileUploaderMixin.dg's$d++rM)NNNNN)rjstrrkstr | Sequence[str] | NonerALiteral[True, 'directory']rl Key | Nonerm str | NonernWidgetCallback | NoneroWidgetArgs | NonerpWidgetKwargs | Nonereboolrfrrgrr[list[UploadedFile])FNNNNN)rjrrkrrALiteral[False]rlrrmrrnrrorrprrerrfrrgrr[UploadedFile | None)rjrrArrkrrlrrmrrnrrorrprrerrfrrgrr[r)rjrrArrkrrlrrmrrnrrorrprrerrfrrgrr[r)NFNNNNN)rjrrkrrAr)rlrrmrrnrrorrprrerrfrrgrr[(UploadedFile | list[UploadedFile] | None)rjrrkrrAr)rlrrmrrnrrorrprrfrrerr6zScriptRunContext | Nonergrr[r)r[r&) r\r]r^r rqrrypropertyrr`rMr=rbrbsE +/"&&*!,5%.!!)! : !  !  !)! !$!!*!#! !!$ 16+/"&&*",5%."")" . "  "  ")" "$""*"#" "". ,0+/"&&*,5%.!! : ! ) !  !!)! !$!!*!#! !!$ 16+/+/"&&*,5%."" . " ) "  "")" "$""*"#" "" O$,05:+/"&&*O ,5%.O O )O  3 O  O  O )O  O $O O *O #O  2O %O h,05:+/"&&*]"-6'+%.]"]")]" 3 ]"  ]"  ]")]" ]"$]"*]"]"%]"#]" 2]"~,,rMrb)r5rZr[z list[UploadedFile | DeletedFile])A __future__r dataclassesrtextwraprtypingrrrr r streamlitr *streamlit.elements.lib.file_uploader_utilsr r !streamlit.elements.lib.form_utilsr#streamlit.elements.lib.layout_utilsrrrstreamlit.elements.lib.policiesrrstreamlit.elements.lib.utilsrrrrrstreamlit.proto.Common_pb2rrPrUploadedFileInfoProto streamlit.proto.FileUploader_pb2rrstreamlit.runtime.metrics_utilrstreamlit.runtime.scriptrunnerrrstreamlit.runtime.staterr r!r"'streamlit.runtime.uploaded_file_managerr#r$collections.abcr%streamlit.delta_generatorr&rQr'r_rr)r>r@rbr`rMr=rs#!DD> SPN9O N(8;l[&@!AADH9"& (